List, Stack and Queue

# List, Stack and Queue - Lists Stacks and Queues Abstract...

This preview shows pages 1–10. Sign up to view the full content.

1 Lists, Stacks and Queues Abstract Data Types (ADTs) z An abstract data type (ADT) is a set of operations. z Abstract data types are mathematical abstractions . z Nowhere in an ADT's definition is there any mention of how the set of operations is implemented.

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

View Full Document
2 ADT z Objects such as list , sets , and graphs , along with their operations, can be viewed as abstract data types, just as integers , reals , and booleans are data types. z There is no rule telling us which operations must be supported for each ADT; this is a design decision . z Error handling and tie breaking (where appropriate) are also generally up to the program designer.
3 ADTs z We will see how each can be implemented in several ways. z If they are done correctly, the programs that use them will not need to know which implementation was used.

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

View Full Document
4 ADT Example z For the set ADT, we might have such operations as union , intersection , size , and complement . z Alternately, we might only want the two operations union and find , which would define a different ADT on the set.
5 The List ADT z We will deal with a general list of the form a 1 , a 2 , …, a n . z We say that the size of this list is n . z We will call the special list of size 0 a null list . z For any list except the null list, we say that a i +1 follows (or succeeds) a i ( i < n ) and that a i -1 precedes a i ( i > 1).

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

View Full Document
6 The List ADT z The first element of the list is a 1 , and the last element is a n . z The predecessor of a 1 and the successor of a n are not defined. z The position of element a i in a list is i .
7 Lists -- Definition z A list of elements of type T is a finite sequence of elements of T together with the following operations: Create the list and make it empty . Check if the list is empty . Check if the list is full . Find the size of the list.

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

View Full Document
8 Lists -- Definition Retrieve any entry from the list, not empty. Replace an entry by a new entry at any position in the list, not empty. Insert a new entry into the list at any position, provided that the list is not full. Delete any entry from the list, provided that the list is not empty. Clear the list to make it empty.
9 Lists -- Operations z bool isEmpty( ) const; z void makeEmpty( ); z ListItr<Object> zeroth( ) const; z ListItr<Object> first( ) const; z void insert( const Object & x, const ListItr<Object> & p ); z ListItr<Object> find( const Object & x ) const; z ListItr<Object> findPrevious( const Object & x ) const; z void remove( const Object & x );

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 53

List, Stack and Queue - Lists Stacks and Queues Abstract...

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

View Full Document
Ask a homework question - tutors are online