





















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Prof. Gangesh Charu delivered this lecture at Alagappa University for Data Structures course. Its main points are: Linked, Lists, Stacks, Queues, Abstract, Data, Types, ADT, Operations, Implementation, Operations, Simple, Array
Typology: Slides
1 / 93
This page cannot be seen from the preview
Don't miss anything!






















































































On special offer
7/7/2012 Lists, Stacks, and Queues 3-
EE 232 Data Structures Session-05 , Spring-
7/7/2012 Lists, Stacks, and Queues 3-
7/7/2012 Lists, Stacks, and Queues 3-
7/7/2012 Lists, Stacks, and Queues 3-
Data type a set of objects + a set of operations
Example integer
7/7/2012 Lists, Stacks, and Queues 3-
Why do we call it abstract?
In an ADT’s definition, it is not mentioned how to implement the set of operations
ADTs are not directly usable
They have to be implemented
A given ADT may have more than one implementation
7/7/2012 Lists, Stacks, and Queues 3-
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Operations
PrintList : prints the list MakeEmpty : create an empty list Find : returns the position of an object in a list
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
The List ADT can be implemented using an array or a linked list
Simple array implementation Elements are stored in contiguously
an estimate of the maximum size of the list is required and this usually requires a high overestimate, which wastes considerable space
4 -3 5 -2 -1 2 6 -2 1 - A 1 A N
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Linked Lists consists of a series of structures, which are not necessarily adjacent in memory Each structure or node contains the element and a pointer (called Next ) to a structure containing its successor
A 1 A N
4 -3 (^) …….. -1 NULL
A node in the list
Pointer is a variable that contains the address where some other data are stored
Conceptual view
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Running time of the operations
PrintList (L) Find (L, key) FindKth (L,i) takes O ( i )
A 1 800 A 2 712 A 3 992 A 4 692 A 5 0 1000 800 712 992 692 Actual view
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Deletion from a Linked List Requires one pointer change
Running time O (1)
NULL A 1 A 4
4 -3 5 -
A 3 delete
A 2
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Array versus Linked Lists
Linked lists are more complex to code and manage than arrays, but they have some distinct advantages Dynamic
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
#ifndef _List_H #define _List_H struct Node; typedef struct Node* PtrToNode; typedef PtrToNode List; typedef PtrToNode Position; List MakeEmpty( List L ); int IsEmpty( List L ); int IsLast( Position P, List L ); Position Find( ElementType X, List L ); void Delete( ElementType X, List L ); Position FindPrevious( ElementType X, List L ); void Insert( ElementType X, List L, Position P ); void DeleteList( List L ); Position Header( List L ); Position First( List L ); Position Advance( Position P ); ElementType Retrieve( Position P );
#endif /* _List_H */
struct Node { ElementType Element; Position Next; };
Programming Details…
7/7/2012 Lists, Stacks, and Queues 3-
The List ADT…
Programming Details…
/* Return true if L is empty */
int IsEmpty( List L ) { return L->Next == NULL; }
Running time?