Lecture06

Lecture06 - CMPSC24:Lecture6 AbstractDataType:Lists...

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

View Full Document Right Arrow Icon
CMPSC 24: Lecture 6 Abstract Data Type: Lists Divyakant Agrawal Department of Computer Science UC Santa Barbara 4/14/10 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
LIST ADT 4/14/10 2
Background image of page 2
3 Sorted and Unsorted List ADTs UNSORTED LIST Elements are placed into the list in no par;cular order. SORTED LIST List elements are in a sorted order‐‐‐either numerically or alphabe;cally by the elements themselves, or by a component of the element (called a KEY member). Name some possible keys 4/14/10
Background image of page 3

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

View Full DocumentRight Arrow Icon
ADT Unsorted List Transformers MakeEmpty InsertItem DeleteItem Observers IsFull GetLength RetrieveItem Iterators ResetList GetNextItem change state observe state process all 4 4/14/10
Background image of page 4
ADT Unsorted List Common vocabulary loca/on accesses a par/cular element Node(loca/on) is all data of element Info(loca/on) is the user's data at loca/on Info(last) is the user's data at the last loca/on Next(loca/on) is the node following Node(loca/on) Two implementa/ons 5 4/14/10
Background image of page 5

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

View Full DocumentRight Arrow Icon
// SPECIFICATION FILE ( unsortedType.h ) #include “ItemType.h” class UnsortedType // declares a class data type { public : // 8 public member functions UnsortedType(); void MakeEmpty( ); bool IsFull( ) const; int GetLength( ) const; // returns length of list void RetrieveItem( ItemType& item, bool& found ); void InsertItem( ItemType item ); void DeleteItem( ItemType item ); void ResetList( ); item ); } Public declara/ons are the same for both implementa/ons; only private data changes What is ItemType? 6 SpecifcaKon 4/14/10
Background image of page 6
Generic Data Type A type for which the operaKons are deFned but the types of the items being manipulated are not deFned How can we make the items on the list generic? List items are of class ItemType, which has a ComparedTo funcKon that returns ( LESS , GREATER , EQUAL ) 7 4/14/10
Background image of page 7

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

View Full DocumentRight Arrow Icon
Array‐Based ImplementaKon Private data members for array‐based implementaKon private int length; ItemType info[MAX_ITEMS]; int currentPos; }; Where does MAX_ITEMS come from? 8 4/14/10
Background image of page 8
Array‐Based ImplementaKon No/ce the diference between the array and the list stored in the array Array‐based implementa/on 9 4/14/10
Background image of page 9

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

View Full DocumentRight Arrow Icon
A special member funcKon of a class that is implicitly invoked when a class object is deFned What should the constructor do? UnsortedType::UnsortedType() { length = 0; } Constructor 10 4/14/10
Background image of page 10
What is a full list? An empty list? bool UnsortedType::IsFull() { return (length == MAX_ITEMS); } bool UnsortedType::IsEmpty() { return (length == 0); } Checking for full and empty lists 11 4/14/10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Insert length 3 info [0] Maxwell [1] Bradley [2] Asad [3] . . . [MAX_ITEMS-1] If the list is unsorted, where should the next element go ? insert(“Doe"); 12 4/14/10
Background image of page 12
length 4 info [0] Maxwell [1] Bradley [2] Asad [3] Doe [MAX_ITEMS-1] insert(“Doe"); That was easy! Can you
Background image of page 13

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

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

This note was uploaded on 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

Page1 / 52

Lecture06 - CMPSC24:Lecture6 AbstractDataType:Lists...

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

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