List ADT
List ADT
B.Bhuvaneswaran
Assistant Professor (SS)
Department of Computer Science & Engineering
Rajalakshmi Engineering College
Thandalam
Chennai 602 105
bhuvaneswaran@rajalakshmi.edu.in
Advantages
Advantages
Abstract Data type is an extension of
modular design.
An abstract data type is a set of
operations such as Union, Intersection,
Complement, Find etc.,
The basic idea of implementing ADT is that
the operations are written once in
program and can be called by any part of
the program.
Find routine
Position Find (int X, List L)
{
// Returns the position of X in L
// NULL if X is not found
Position P;
P = L->Next;
while (P != NULL && P->Element != X)
P = P->Next;
return P;
}
FindPrevious routine
position FindPrevious (int X, List L)
{
// Returns the position of the predecessor
Position P;
P = L;
while(P->Next!=NULL && P->Next->Element!=X)
P = P->Next;
return P;
)
FindNext routine
position FindNext (int X, List L)
{
// Returns the position of its successor
P = L->Next;
while(P->Next!=NULL && P->Element!=X)
P = P->Next;
return P->Next;
}
Structure declaration
struct Node
{
int Element;
struct Node *FLINK;
struct Node *BLINK
};
Advantage
Deletion operation is easier.
Finding the predecessor & Successor of a
node is easier.
Disadvantage
Polynomial ADT
else
{
else
{
Polynomial differentiation
void diff ( )
{
poly *ptr1, *newnode;
ptr1 = list1;
while (ptr1 != NULL)
{
newnode = malloc (sizeof (struct poly));
newnode->coeff = ptr1->coeff*ptr1->power;
newnode->power = ptr1->power - 1 ;
newnode->next = NULL;
list3 = create (list3, newnode);
ptr1 = ptr1->next;
}
}
Pass 1
Pass 2
Pass 3
Multi Lists
More complicated application of linked list
is multilist.
It is useful to maintain student
registration, employee involved in
different projects etc.,
Multilist saves space but takes more time
to implement.
Cursor Implementation
Initialized cursorspace
Declaration
typedef int ptrtoNode;
typedef ptrtoNode position;
void Initialize cursorspace (void);
int IsEmpty (List L);
int IsLast (position P, List L);
position Find (int X, List L);
void Delete (int X, List L);
void Insert (int X, List L, position P);
struct Node
{
int Element;
position Next;
};
struct Node Cursorspace [space size];
References
Mark Allen Weiss, Data Structures and
Algorithm Analysis in C++, 3rd Edition,
Pearson Education, 2006.
P.Revathy, Dr.S.Poonkuzhali, Data
Structures and Algorithms, 1st Edition,
Charulatha Publications, 2009.