The Container Class A Collection of Data. What is a Container Class?  A class that can contain a collection of items  A list or bag of items of the.

Slides:



Advertisements
Similar presentations
UNIT IV.
Advertisements

JAVA & Linked List Implementation
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
Review Pseudo Code Basic elements of Pseudo code
Computer Science 112 Fundamentals of Programming II Overview of Collections.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Review Learn about linked lists
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Implementation options There are two basic approaches: –array-based –linked We will consider array-based implementation first Use a TDD approach: first.
1 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
hashing1 Hashing It’s not just for breakfast anymore!
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Alice in Action with Java
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Summary of lectures (1 to 11)
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Programming Logic and Design Fourth Edition, Comprehensive
1 Fall Chapter 4 ADT Sorted List. 2 Goals Describe the Abstract Data Type Sorted List from three perspectives Implement the following Sorted List.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Chapter 13 Lists. List  List  A variable-length, linear collection of homogeneous components  Example  StudentRec Students[100];  A list of 100 students.
Topic 3 The Stack ADT.
Data Structures Using C++ 2E
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
Linked Lists Tonga Institute of Higher Education.
1. The term STL stands for ? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
1 Searching Searching in a sorted linked list takes linear time in the worst and average case. Searching in a sorted array takes logarithmic time in the.
Hashing Hashing is another method for sorting and searching data.
(c) University of Washington15-1 CSC 143 Java List Implementation via Arrays Reading: 13.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Computer Science 112 Fundamentals of Programming II Implementation Strategies for Unordered Collections.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Array Lists1 © 2010 Goodrich, Tamassia. Array Lists2 The Array List ADT  The Array List ADT extends the notion of array by storing a sequence of arbitrary.
Arrays1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
1 Data Organization Example 1: Heap storage management –Keep track of free chunks of memory Example 2: A simple text editor –Maintain a sequence of lines.
Review Sorting algorithms Selection Sort Insertion Sort Bubble Sort Merge Sort Quick Sort.
Linked List Containers. Linked Lists List consists of multiple listnodes List consists of multiple listnodes Each listnode consists of Each listnode consists.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
COM S 207 ArrayList Instructor: Ying Cai Department of Computer Science Iowa State University
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
1 Chapter 6 Methods for Making Data Structures. 2 Dynamic Arrays in Data Structures In almost every data structure, we want functions for inserting and.
Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
REEM ALMOTIRI Information Technology Department Majmaah University.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Chapter 5 Record Storage and Primary File Organizations
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
3/19/2016 5:40 PMLinked list1 Array-based List v.s. Linked List Yumei Huo Department of Computer Science College of Staten Island, CUNY Spring 2009.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Linked List ADT used to store information in a list
Review Array Array Elements Accessing array elements
CHP - 9 File Structures.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Linked List and Selection Sort
Introduction to Data Structure
Data Structures & Algorithms
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Dynamic Array: Implementation of Stack
Presentation transcript:

The Container Class A Collection of Data

What is a Container Class?  A class that can contain a collection of items  A list or bag of items of the same data type  Implementation of the container is encapsulated  Members of the container class provide member functions needed to handle the container data.  Client does not have to deal directly with the data structure being used in the container

Logical Implementations  Two logical implementations of containers  Array-based implementations  Objects in the container are kept in an array  Linked list-based implementations  Objects in the container are kept in a linked list  Member Functions should logically include:  Add item  Remove item  Get next item  Query state of container  Total size  Total capacity

Array-Based Implementation  Set initial state: constructor  Add item: adds a new item into the container  Remove item: removes an index item matching a search pattern  Get next item: reveals the current index + 1  Query state of container  Total Size Used: last valid array index containing data  Total Capacity: valid array indexes range from [0] to array length -1

Array Implementation  Contiguous memory  Direct access by index  Must declare extra variables to track size and capacity  C++ raw array doesn’t know its own size  Index arithmetic to move forward or backward  Will follow index to spot in memory, even if it is out of bounds  Insert/delete operations easiest at the end of the array  Difficult to make an array larger  Can’t just tack on more space at the end

Track Array Properties  Size: initial size of the array.  This is usually the total number of spaces allotted  Used: number of index slots currently holding data

Track Array Properties  Operations that change the array should also track size and used properties  Insert new_entry to the array data, then add one to member variable used data[used] = new_entry; used++; …or… data[used++] = new_entry;

Difficult to Add to the Beginning of an Array  Easiest to add data to the END of an array  May need to insert into middle or beginning of an array if the data must be sorted  To add data at the beginning of an array:  Move each existing data element over to make space  Be careful not to overwrite data

How Client Uses Your Container Class  #include “mybag.h”  Create an object of the bag type  Class name is the data type of the object  Call functions to handle the data in the bag using object name with dot operator