{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# DS-chapter3(ADT,List) - 3 Lists Stacks and Queues CHAPTER...

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

CHAPTER 3 Lists, Stacks, and Queues 3.1 Abstract Data Type (ADT) H Definition i Data Type = { Objects } { Operations } i Example H int = { 0, ± 1, ± 2, , INT_MAX, INT_MIN } { + , - , × , ÷ , % , } H Definition i An Abstract Data Type (ADT) is a data type that is organized in such a way that the specification on the objects and specification of the operations on the objects are separated from the representation of the objects and the implementation on the operations.

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

View Full Document
Objects : ( item 0 , item 1 , ⋅ ⋅ ⋅ , item N - 1 ), the size of this list is N The empty list: the list size is 0 ADT: The List ADT A i+1 follows ( or succeeds) A i ( i< N) A i-1 precedes A i ( i>1) The first element of the list is A 1 The last element of the list is A N The position of the element A i in a list is i

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

View Full Document
Operations : Finding the length , N , of a list. Printing all the items in a list. Making an empty list. Finding the k- th item from a list, 0 k < N . Inserting a new item after the k -th item of a list, 0 k < N . Deleting an item from a list. Finding next of the current item from a list. Finding previous of the current item from a list. Why after? The List ADT
1. Simple Array implementation of Lists The List ADT array[ i ] = item i MaxSize has to be estimated. Address Content array+i item i array+i+1 item i+1 …… …… …… …… Sequential mapping H Find_Kth takes O(1) time. Insertion and Deletion not only take O( N ) time, but also involve a lot of data movements which takes time.

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

View Full Document
The List ADT 2. Linked Lists Address Data Pointer 0010 0011 0110 1011 SUN QIAN ZHAO LI 1011 0010 0011 NULL Head pointer ptr = 0110 ZHAO QIAN SUN LI ptr NULL Initialization: typedef struct list_node *list_ptr; typedef struct list_node { char data [ 4 ] ; list_ptr next ; } ; list_ptr
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 20

DS-chapter3(ADT,List) - 3 Lists Stacks and Queues CHAPTER...

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

View Full Document
Ask a homework question - tutors are online