Ch3 - C+ Plus Data Structures Nell Dale Chapter 3 ADTs...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Nell Dale Chapter 3 ADTs Unsorted List and Sorted List Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus C++ Plus Data Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Abstract Data Type (ADT) A data type whose properties (domain and operations) are specified independently of any particular implementation.
Background image of page 2
3 Application (or user) level: modeling real-life data in a specific context. Logical (or ADT) level: abstract view of the domain and operations. WHAT Implementation level: specific representation of the structure to hold the data items, and the coding for operations. HOW Data from 3 different levels
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Basic Kinds of ADT Operations Constructor -- creates a new instance (object) of an ADT. Transformer -- changes the state of one or more of the data values of an instance. Observer -- allows us to observe the state of one or more of the data values of an instance without changing them. Iterator -- allows us to process all the components in a data structure sequentially. 4
Background image of page 4
5 What is a List? A list is a homogeneous collection of elements, with a linear relationship between elements. That is, each list element (except the first) has a unique predecessor , and each element (except the last) has a unique successor .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Sorted and Unsorted Lists UNSORTED LIST Elements are placed into the list in no particular order. SORTED LIST List elements are in an order that is sorted in some way -- either numerically or alphabetically by the elements themselves, or by a component of the element (called a KEY member) .
Background image of page 6
ADT Unsorted List Operations Transformers MakeEmpty InsertItem DeleteItem Observers IsFull LengthIs RetrieveItem Iterators ResetList GetNextItem change state observe state process all 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 What is a Generic Data Type? A generic data type is a type for which the operations are defined but the types of the items being manipulated are not defined. One way to simulate such a type for our UnsortedList ADT is via a user-defined class ItemType with member function ComparedTo having enumerated type value LESS , GREATER , or EQUAL .
Background image of page 8
// SPECIFICATION FILE ( unsorted.h ) #include “ItemType.h” class UnsortedType // declares a class data type { public : // 8 public member functions void MakeEmpty ( ) ; bool IsFull ( ) const ; int LengthIs ( ) const ; // returns length of list void RetrieveItem ( ItemType item, bool found ) ; void InsertItem ( ItemType item ) ; void DeleteItem ( ItemType item ) ; void ResetList ( ); void GetNextItem ( ItemType & item ) ; private : // 3 private data members int length ; ItemType info[MAX_ITEMS] ; int currentPos ; } ; 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Class Interface Diagram UnsortedType class IsFull LengthIs ResetList DeleteItem InsertItem MakeEmpty RetrieveItem GetNextItem Private data: length info [ 0 ] [ 1 ] [ 2 ] [MAX_ITEMS-1] currentPos
Background image of page 10
// IMPLEMENTATION FILE ARRAY-BASED LIST ( unsorted.cpp ) #include “itemtype.h” void UnsortedType::MakeEmpty ( ) // Pre: None. // Post: List is empty.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 61

Ch3 - C+ Plus Data Structures Nell Dale Chapter 3 ADTs...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online