Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.

Slides:



Advertisements
Similar presentations
Lists: An internal look
Advertisements

Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Alan YorinksLecture 7 1 • Tonight we will look at:: • List ADT • Unsorted List • Sequential Search • Selection Sort • Sorted List • Binary Search.
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
A Bag Implementation that Links Data Chapter 3 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues and Priority Queues
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Typical operations on data –Add data.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 3 Array-Based Implementations CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Queue, Deque, and Priority Queue Implementations Chapter 11 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Bag Implementations that Use Arrays Chapter 2 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Data Abstraction: The Walls
Sorting Algorithms and their Efficiency Chapter 11 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 3 Data.
Queues and Priority Queues
Implementations of the ADT Stack Chapter 7 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 6 Stacks CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Bags Chapter 1 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
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.
Tree Implementations Chapter 16 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Chapter 13-1 Applied Arrays: Lists and Strings Dale/Weems.
Bag Implementations that Use Arrays Chapter 2 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions.
Stack Implementations Chapter 6 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Heaps Chapter 17 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
C++ Classes C++ Interlude 1 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Sorted Lists Chapter Chapter Contents Specifications for the ADT Sorted List Using the ADT Sorted List A Linked Implementation The Method add The.
Interlude 1 C++ Classes CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Chapter 4 Link Based Implementations
Link Based Implementations
Link-Based Implementations
Data Abstraction: The Walls
Data Abstraction: The Walls
Bag Implementations that Use Arrays
A Bag Implementation that Links Data
Chapter 16 Tree Implementations
C++ Classes C++ Interlude 1
Implementations of the ADT Stack
Chapter 16-2 Linked Structures
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 4 Link Based Implementations
Chapter 3 Array-Based Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
List Implementations Chapter 9
List Implementations Chapter 9.
Stacks Chapter 6 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Array-Based Implementations
Sorted Lists and Their Implementations
Stack Implementations
Array-Based Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Bag Implementations that Use Arrays
Queues and Priority Queue Implementations
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Presentation transcript:

Array-Based Implementations Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Contents Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 The Approach An Array-Based Implementation of the ADT Bag

The Approach Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Review of an ADT  A collection of data and a set of operations on that data  Specifications indicate what the operations do, not how to implement Implementing as class provides way to enforce a wall  Prevents access of data structure in any way other than by using the operations.

The Approach FIGURE 3-1 Violating the wall of ADT operations Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Core Methods Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Methods which do basic tasks  Add  Remove  toVector (for display contents)  Constructors Add and remove methods designed first

Using Fixed-Size Arrays Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Must store  Data item  Its number in the array Keep track of  Max size of the array  Number of items currently stored  Where items were removed from array

Array-Based Implementation Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Private data, see header file, Listing 3-1Listing 3-1 FIGURE 3-2 An array-based implementation of the ADT bag.htm code listing files must be in the same folder as the.ppt files for these links to work

Defining the Core Methods Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 Core methods defined  ArrayBag ::ArrayBag(): itemCount(0), maxItems(DEFAULT_CAPACITY)add  bool ArrayBag ::add( const ItemType& newEntry)  vector ArrayBag :: toVector() const  int ArrayBag ::getCurrentSize() const  bool ArrayBag ::isEmpty() const

Defining the Core Methods FIGURE 3-3 Inserting a new entry into an array-based bag View test program, Listing 3-2 and OutputListing 3-2 Output Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Implementing More Methods int ArrayBag :: getFrequencyOf ( const ItemType& anEntry) const bool ArrayBag ::contains( const ItemType& target) const Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013 FIGURE 3-4 The array items after a successful search for the string "Alice"

Implementing More Methods FIGURE 3-5 (a) A gap in the array items after deleting the entry in items[index] and decrementing itemCount; Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Implementing More Methods FIGURE 3-5 (b) shifting subsequent entries to avoid a gap; Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Implementing More Methods FIGURE 3-5 (c) the array after shifting; Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Implementing More Methods int ArrayBag ::getIndexOf (const ItemType& target) const bool ArrayBag ::remove( const ItemType& anEntry) void ArrayBag ::clear() Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Implementing More Methods FIGURE 3-6 Avoiding a gap in the array while removing an entry Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Using Recursion in the Implementation Recursive version of getIndexOf Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

Using Recursion in the Implementation Recursive version of getFrequencyOf Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013

End Chapter 3 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013