2. Topics to be Covered
Abstract Data Types (ADTs)
List ADT
• Array based implemetation
• Linked implementation
• Singly linked
• Doubly linked
• Circular linked
• Applications
Polynomial Manipulation
Abstract Data Types (ADTs)
List ADT
• Array based implemetation
• Linked implementation
• Singly linked
• Doubly linked
• Circular linked
• Applications
Polynomial Manipulation
Topics to be Covered
3. Abstract Data Types (ADTs)
In the C programming language, data types are declarations fo
memory locations or variables that determine the characteristics o
the data that may be stored and the methods (operations) o
processing that are permitted involving them.
ADT is a mathematical model for data type, which is defined from
point of view of the user of a data.
• Possible values
• Possible operations
Data structures is concrete representation of the data in the point o
view of the implementer.
In the C programming language, data types are declarations fo
memory locations or variables that determine the characteristics o
the data that may be stored and the methods (operations) o
processing that are permitted involving them.
ADT is a mathematical model for data type, which is defined from
point of view of the user of a data.
• Possible values
• Possible operations
Data structures is concrete representation of the data in the point o
view of the implementer.
Abstract Data Types (ADTs)
In the C programming language, data types are declarations fo
memory locations or variables that determine the characteristics o
the data that may be stored and the methods (operations) o
processing that are permitted involving them.
ADT is a mathematical model for data type, which is defined from
point of view of the user of a data.
• Possible values
• Possible operations
Data structures is concrete representation of the data in the point o
view of the implementer.
In the C programming language, data types are declarations fo
memory locations or variables that determine the characteristics o
the data that may be stored and the methods (operations) o
processing that are permitted involving them.
ADT is a mathematical model for data type, which is defined from
point of view of the user of a data.
• Possible values
• Possible operations
Data structures is concrete representation of the data in the point o
view of the implementer.
4. ADT
There is an interface between the ADT and the program(s) that use it.
The lower-level implementation details of the data structure are
hidden from view of the rest of the program.
The implementation details can be changed without altering the ADT
interface.
Abstract Data Type (ADT)
Mathematical description of an object and
the set of operations on the object
Data Types
integer, array,
pointers, …
Abstract Data Type (ADT)
Mathematical description of an object and
the set of operations on the object
Algorithms
binary search, quicksort,
…
ADT
There is an interface between the ADT and the program(s) that use it.
The lower-level implementation details of the data structure are
hidden from view of the rest of the program.
The implementation details can be changed without altering the ADT
interface.
Abstract Data Type (ADT)
Mathematical description of an object and
the set of operations on the object
Abstract Data Type (ADT)
Mathematical description of an object and
the set of operations on the object
Algorithms
binary search, quicksort,
…
5. The Core Operations
Every ADT should provide a way to:
• add an item
• remove an item
• find, retrieve, or access an item
Many, many more possibilities
• is it empty
• make it empty
• give a sub set of it
• and on and on and on…
Many different ways to implement these items each with associated
costs and benefits
Every ADT should provide a way to:
• add an item
• remove an item
• find, retrieve, or access an item
Many, many more possibilities
• is it empty
• make it empty
• give a sub set of it
• and on and on and on…
Many different ways to implement these items each with associated
costs and benefits
The Core Operations
Every ADT should provide a way to:
• add an item
• remove an item
• find, retrieve, or access an item
Many, many more possibilities
• is it empty
• make it empty
• give a sub set of it
• and on and on and on…
Many different ways to implement these items each with associated
costs and benefits
Every ADT should provide a way to:
• add an item
• remove an item
• find, retrieve, or access an item
Many, many more possibilities
• is it empty
• make it empty
• give a sub set of it
• and on and on and on…
Many different ways to implement these items each with associated
costs and benefits
6. Implementing ADTs
When implementing an ADT the operations and behaviors are
lready specified
• Interface
mplementer’s first choice is what to use as the internal storage
ontainer for the concrete data type
• the internal storage container is used to hold the items in the collection
• often an implementation of an ADT initially slim pickings for choice of
storage containers
When implementing an ADT the operations and behaviors are
lready specified
• Interface
mplementer’s first choice is what to use as the internal storage
ontainer for the concrete data type
• the internal storage container is used to hold the items in the collection
• often an implementation of an ADT initially slim pickings for choice of
storage containers
When implementing an ADT the operations and behaviors are
lready specified
• Interface
mplementer’s first choice is what to use as the internal storage
ontainer for the concrete data type
• the internal storage container is used to hold the items in the collection
• often an implementation of an ADT initially slim pickings for choice of
storage containers
When implementing an ADT the operations and behaviors are
lready specified
• Interface
mplementer’s first choice is what to use as the internal storage
ontainer for the concrete data type
• the internal storage container is used to hold the items in the collection
• often an implementation of an ADT initially slim pickings for choice of
storage containers
7. List ADT
A List is a dynamic ordered set of homogeneous elements.
• is a linear sequence of a number of items (need not be in specific order)
• items are of the same data type and can occur more than once
The list has one first element (the head) and one last element. Excep
for the first and the last, each element has one unique predecesso
and one unique successor.
We will consider a general list of the form A1, A2, A3, …, AN .
• Size is N
• If Size is 0 – Empty List
• Position of Ai in the list is i
A List is a dynamic ordered set of homogeneous elements.
• is a linear sequence of a number of items (need not be in specific order)
• items are of the same data type and can occur more than once
The list has one first element (the head) and one last element. Excep
for the first and the last, each element has one unique predecesso
and one unique successor.
We will consider a general list of the form A1, A2, A3, …, AN .
• Size is N
• If Size is 0 – Empty List
• Position of Ai in the list is i
List ADT
A List is a dynamic ordered set of homogeneous elements.
• is a linear sequence of a number of items (need not be in specific order)
• items are of the same data type and can occur more than once
The list has one first element (the head) and one last element. Excep
for the first and the last, each element has one unique predecesso
and one unique successor.
We will consider a general list of the form A1, A2, A3, …, AN .
• Size is N
• If Size is 0 – Empty List
• Position of Ai in the list is i
A List is a dynamic ordered set of homogeneous elements.
• is a linear sequence of a number of items (need not be in specific order)
• items are of the same data type and can occur more than once
The list has one first element (the head) and one last element. Excep
for the first and the last, each element has one unique predecesso
and one unique successor.
We will consider a general list of the form A1, A2, A3, …, AN .
• Size is N
• If Size is 0 – Empty List
• Position of Ai in the list is i
8. Generic Operations on a list
Create an empty list
Print all elements of a list
Construct a copy of the list
Find the position of an element in a list
Remove an element from the list
Insert an element into particular position in the list
Check if the list is empty
Remove all the elements from the list
Retrieve an element from a specific position in the list
Create an empty list
Print all elements of a list
Construct a copy of the list
Find the position of an element in a list
Remove an element from the list
Insert an element into particular position in the list
Check if the list is empty
Remove all the elements from the list
Retrieve an element from a specific position in the list
Generic Operations on a list
Create an empty list
Print all elements of a list
Construct a copy of the list
Find the position of an element in a list
Remove an element from the list
Insert an element into particular position in the list
Check if the list is empty
Remove all the elements from the list
Retrieve an element from a specific position in the list
Create an empty list
Print all elements of a list
Construct a copy of the list
Find the position of an element in a list
Remove an element from the list
Insert an element into particular position in the list
Check if the list is empty
Remove all the elements from the list
Retrieve an element from a specific position in the list
9. Operations on List
Create( ) – Create a List
Insert(X, p) – Insert the element X at the position p.
Delete(X) – Delete the element X
Find(X) – Return the position of X
Next(X) – Returns the element/position that succeeds X.
Next(p) – Returns the element in p+1
Previous(p) – Returns the element in p-1
Previous(X) – Returns the element/position that precedes X.
PrintList – Display the contents of the List.
MakeEmpty/DeleteAll-Makes the list empty.
IsEmpty- Returns true if the list does not have any element
IsFull- Returns true if the list cannot hold another element (full)
Create( ) – Create a List
Insert(X, p) – Insert the element X at the position p.
Delete(X) – Delete the element X
Find(X) – Return the position of X
Next(X) – Returns the element/position that succeeds X.
Next(p) – Returns the element in p+1
Previous(p) – Returns the element in p-1
Previous(X) – Returns the element/position that precedes X.
PrintList – Display the contents of the List.
MakeEmpty/DeleteAll-Makes the list empty.
IsEmpty- Returns true if the list does not have any element
IsFull- Returns true if the list cannot hold another element (full)
Operations on List
Create( ) – Create a List
Insert(X, p) – Insert the element X at the position p.
Delete(X) – Delete the element X
Find(X) – Return the position of X
Next(X) – Returns the element/position that succeeds X.
Next(p) – Returns the element in p+1
Previous(p) – Returns the element in p-1
Previous(X) – Returns the element/position that precedes X.
PrintList – Display the contents of the List.
MakeEmpty/DeleteAll-Makes the list empty.
IsEmpty- Returns true if the list does not have any element
IsFull- Returns true if the list cannot hold another element (full)
Create( ) – Create a List
Insert(X, p) – Insert the element X at the position p.
Delete(X) – Delete the element X
Find(X) – Return the position of X
Next(X) – Returns the element/position that succeeds X.
Next(p) – Returns the element in p+1
Previous(p) – Returns the element in p-1
Previous(X) – Returns the element/position that precedes X.
PrintList – Display the contents of the List.
MakeEmpty/DeleteAll-Makes the list empty.
IsEmpty- Returns true if the list does not have any element
IsFull- Returns true if the list cannot hold another element (full)
10. Array Implementation of List
An Array is used for storing all the list elements.
Index or subscript is used as address or position of element in the array
Even if the array is dynamically allocated, an estimate of the maximum size
of the list is required when the execution of the program starts.
In many a situations over-estimate would be done, which waste
considerable space. This could be a serious limitation, especially if there
are many lists of unknown size.
An Array is used for storing all the list elements.
Index or subscript is used as address or position of element in the array
Even if the array is dynamically allocated, an estimate of the maximum size
of the list is required when the execution of the program starts.
In many a situations over-estimate would be done, which waste
considerable space. This could be a serious limitation, especially if there
are many lists of unknown size.
Array Implementation of List
An Array is used for storing all the list elements.
Index or subscript is used as address or position of element in the array
Even if the array is dynamically allocated, an estimate of the maximum size
of the list is required when the execution of the program starts.
In many a situations over-estimate would be done, which waste
considerable space. This could be a serious limitation, especially if there
are many lists of unknown size.
An Array is used for storing all the list elements.
Index or subscript is used as address or position of element in the array
Even if the array is dynamically allocated, an estimate of the maximum size
of the list is required when the execution of the program starts.
In many a situations over-estimate would be done, which waste
considerable space. This could be a serious limitation, especially if there
are many lists of unknown size.
11. Array Implementation of List
de<stdio.h>
t, i, size=0, pos, ele, n; //list[100];
eate (); void insert(int,int);
nd(); void delete(); void display();
choice;
"n1. Create List 2. Insert Position 3. Display
4. Delete Position 5. Find 6. Exitn");
"Enter your choice :");
"%d",&choice);
choice != 6)
ch(choice) {
: create();break;
case 2: printf("Enter the Position :");
scanf("%d",&pos);
printf("Enter the new element to be inserted :");
scanf("%d",&ele);
insert(ele,pos);break;
case 3: display();break;
case 4: delete();break; case 5: find();break; case 6:
break;
default : printf("nInvalid Choice"); }
printf("n1. Create List 2. Insert Position 3. Display L
4. Delete Position 5. Find 6. Exitn");
printf("nEnter your choice :");
scanf("%d",&choice); } }
de<stdio.h>
t, i, size=0, pos, ele, n; //list[100];
eate (); void insert(int,int);
nd(); void delete(); void display();
choice;
"n1. Create List 2. Insert Position 3. Display
4. Delete Position 5. Find 6. Exitn");
"Enter your choice :");
"%d",&choice);
choice != 6)
ch(choice) {
: create();break;
case 2: printf("Enter the Position :");
scanf("%d",&pos);
printf("Enter the new element to be inserted :");
scanf("%d",&ele);
insert(ele,pos);break;
case 3: display();break;
case 4: delete();break; case 5: find();break; case 6:
break;
default : printf("nInvalid Choice"); }
printf("n1. Create List 2. Insert Position 3. Display L
4. Delete Position 5. Find 6. Exitn");
printf("nEnter your choice :");
scanf("%d",&choice); } }
Array Implementation of List
case 2: printf("Enter the Position :");
scanf("%d",&pos);
printf("Enter the new element to be inserted :");
scanf("%d",&ele);
insert(ele,pos);break;
case 3: display();break;
case 4: delete();break; case 5: find();break; case 6:
break;
default : printf("nInvalid Choice"); }
printf("n1. Create List 2. Insert Position 3. Display L
4. Delete Position 5. Find 6. Exitn");
printf("nEnter your choice :");
scanf("%d",&choice); } }
case 2: printf("Enter the Position :");
scanf("%d",&pos);
printf("Enter the new element to be inserted :");
scanf("%d",&ele);
insert(ele,pos);break;
case 3: display();break;
case 4: delete();break; case 5: find();break; case 6:
break;
default : printf("nInvalid Choice"); }
printf("n1. Create List 2. Insert Position 3. Display L
4. Delete Position 5. Find 6. Exitn");
printf("nEnter your choice :");
scanf("%d",&choice); } }
12. Array Implementation of List
oid create(void)
printf("Enter Size of List:");
scanf("%d",&size); //10
st = (int*)malloc(sizeof(int)*size);
printf("Enter No of elements to be
inserted :");
canf("%d",&n); //4
printf("Enter the elements of list :");
or(i=0;i<n;i++)
canf("%d",list+i); //45,65,23,44
oid create(void)
printf("Enter Size of List:");
scanf("%d",&size); //10
st = (int*)malloc(sizeof(int)*size);
printf("Enter No of elements to be
inserted :");
canf("%d",&n); //4
printf("Enter the elements of list :");
or(i=0;i<n;i++)
canf("%d",list+i); //45,65,23,44
45
45
45 65
45 65
Array Implementation of List
65 23 44
65
65 23
14. Array Implementation of List
find(void)
f("Enter the element to be searched :");
f("%d",&ele); //23
=0;i<n;i++)
[i]==ele)
f("Element %d is found in position %d",ele,i+1);
n;
f("Element is not in the list");
find(void)
f("Enter the element to be searched :");
f("%d",&ele); //23
=0;i<n;i++)
[i]==ele)
f("Element %d is found in position %d",ele,i+1);
n;
f("Element is not in the list");
Array Implementation of List
45 16 65 23 44
15. Array Implementation of List
oid delete(void)
rintf("Enter the Position :"); //2
canf("%d",&pos);
or(i=pos-1;i<=n;i++) list[i]=list[i+1];
--;
oid display(size)
or(i=0;i<size;i++)
rintf("%d ",list[i]);
n=5
n=5
n=5
n=4
oid delete(void)
rintf("Enter the Position :"); //2
canf("%d",&pos);
or(i=pos-1;i<=n;i++) list[i]=list[i+1];
--;
oid display(size)
or(i=0;i<size;i++)
rintf("%d ",list[i]);
n=5
n=5
n=5
n=4
Array Implementation of List
n=5
n=5
n=5
n=4
45 16 65 23 44
45 65 65 23 44
n=5
n=5
n=5
n=4
45 65 23 23 44
45 65 23 44 44
16. Linked Implementation of List
In order to overcome the problem of allocating oversized memory for
the list a pointer implementation of the list can be done.
Pointer implementation of the list is referred to as Linked List as
every element of the list is stored in a node that can hold the data
and a pointer to the successor node in the list.
The last node of the list will be pointing to nothing i.e. it will be made
as NULL
In order to overcome the problem of allocating oversized memory for
the list a pointer implementation of the list can be done.
Pointer implementation of the list is referred to as Linked List as
every element of the list is stored in a node that can hold the data
and a pointer to the successor node in the list.
The last node of the list will be pointing to nothing i.e. it will be made
as NULL
Linked Implementation of List
In order to overcome the problem of allocating oversized memory for
the list a pointer implementation of the list can be done.
Pointer implementation of the list is referred to as Linked List as
every element of the list is stored in a node that can hold the data
and a pointer to the successor node in the list.
The last node of the list will be pointing to nothing i.e. it will be made
as NULL
In order to overcome the problem of allocating oversized memory for
the list a pointer implementation of the list can be done.
Pointer implementation of the list is referred to as Linked List as
every element of the list is stored in a node that can hold the data
and a pointer to the successor node in the list.
The last node of the list will be pointing to nothing i.e. it will be made
as NULL
17. Types of Linked List
Linear Linked List
• Singly Linked
• Doubly Linked
Circular Linked List
• Singly Linked
• Doubly Linked
Linear Linked List
• Singly Linked
• Doubly Linked
Circular Linked List
• Singly Linked
• Doubly Linked
Types of Linked List
18. Implementation of Linked List
arations
def struct node *node_ptr;
t node
ent_type element;
_ptr next;
def node_ptr LIST;
def node_ptr position;
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(struct
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = NULL;
printf("Link List Created Successfully...");
return(tmpcell);
}
arations
def struct node *node_ptr;
t node
ent_type element;
_ptr next;
def node_ptr LIST;
def node_ptr position;
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(struct
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = NULL;
printf("Link List Created Successfully...");
return(tmpcell);
}
Implementation of Linked List
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(struct
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = NULL;
printf("Link List Created Successfully...");
return(tmpcell);
}
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(struct
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = NULL;
printf("Link List Created Successfully...");
return(tmpcell);
}
19. Insert (29,35,76 at beginning)
d insert( element_type x, LIST L, position p )
osition tmp_cell;
mp_cell=(position)malloc(sizeof(struct node));
( tmp_cell == NULL )
fatal_error("Out of space!!!");
se
mp_cell->element = x; tmp_cell->next = p->next;
->next = tmp_cell;
d insert( element_type x, LIST L, position p )
osition tmp_cell;
mp_cell=(position)malloc(sizeof(struct node));
( tmp_cell == NULL )
fatal_error("Out of space!!!");
se
mp_cell->element = x; tmp_cell->next = p->next;
->next = tmp_cell;
Insert (29,35,76 at beginning)
d insert( element_type x, LIST L, position p )
osition tmp_cell;
mp_cell=(position)malloc(sizeof(struct node));
( tmp_cell == NULL )
fatal_error("Out of space!!!");
se
mp_cell->element = x; tmp_cell->next = p->next;
->next = tmp_cell;
d insert( element_type x, LIST L, position p )
osition tmp_cell;
mp_cell=(position)malloc(sizeof(struct node));
( tmp_cell == NULL )
fatal_error("Out of space!!!");
se
mp_cell->element = x; tmp_cell->next = p->next;
->next = tmp_cell;
20. Find (73)
position find ( element_type x, LIST L )
position p;
p = L->next;
while( (p != NULL) && (p->element != x) )
p = p->next;
eturn p;
position find ( element_type x, LIST L )
position p;
p = L->next;
while( (p != NULL) && (p->element != x) )
p = p->next;
eturn p;
position find ( element_type x, LIST L )
position p;
p = L->next;
while( (p != NULL) && (p->element != x) )
p = p->next;
eturn p;
position find ( element_type x, LIST L )
position p;
p = L->next;
while( (p != NULL) && (p->element != x) )
p = p->next;
eturn p;
21. Find previous(56)
tion find_previous( element_type x, LIST L )
tion p;
;
e((p->next != NULL)&&(p->next->element != x))
p->next;
rn p;
tion find_previous( element_type x, LIST L )
tion p;
;
e((p->next != NULL)&&(p->next->element != x))
p->next;
rn p;
tion find_previous( element_type x, LIST L )
tion p;
;
e((p->next != NULL)&&(p->next->element != x))
p->next;
rn p;
tion find_previous( element_type x, LIST L )
tion p;
;
e((p->next != NULL)&&(p->next->element != x))
p->next;
rn p;
22. Delete(35)
oid delete( element_type x, LIST L )
position p, tmp_cell;
p = find_previous( x, L );
f( p->next != NULL
mp_cell = p->next;
p->next = tmp_cell->next;
ree( tmp_cell );
oid delete( element_type x, LIST L )
position p, tmp_cell;
p = find_previous( x, L );
f( p->next != NULL
mp_cell = p->next;
p->next = tmp_cell->next;
ree( tmp_cell );
23. Delete List
oid delete_list( LIST L )
osition p,tmp;
= L->next;
->next = NULL;
while( p != NULL )
mp=p->next;
ree( p );
p = tmp;
oid delete_list( LIST L )
osition p,tmp;
= L->next;
->next = NULL;
while( p != NULL )
mp=p->next;
ree( p );
p = tmp;
24. Other routines
nt is_empty( LIST L )
eturn( L->next == NULL );
nt is_last( position p, LIST L )
eturn( p->next == NULL );
true
false
If p is 800 it would return a false
If p is 712 it would return a true
nt is_empty( LIST L )
eturn( L->next == NULL );
nt is_last( position p, LIST L )
eturn( p->next == NULL );
true
false
If p is 800 it would return a false
If p is 712 it would return a true
Other routines
true
false
If p is 800 it would return a false
If p is 712 it would return a true
true
false
If p is 800 it would return a false
If p is 712 it would return a true
25. Implementation of Linked List
ct node;
edef int element_type;
def struct node *node_ptr;
t node
ent_type element;
_ptr next;
def node_ptr LIST;
def node_ptr position;
struct Node;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node
{ ElementType Element;
Position Next;
Position Prev; };
typedef PtrToNode List;
typedef PtrToNode Position;
ct node;
edef int element_type;
def struct node *node_ptr;
t node
ent_type element;
_ptr next;
def node_ptr LIST;
def node_ptr position;
struct Node;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node
{ ElementType Element;
Position Next;
Position Prev; };
typedef PtrToNode List;
typedef PtrToNode Position;
Implementation of Linked List
struct Node;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node
{ ElementType Element;
Position Next;
Position Prev; };
typedef PtrToNode List;
typedef PtrToNode Position;
struct Node;
typedef int ElementType;
typedef struct Node *PtrToNode;
struct Node
{ ElementType Element;
Position Next;
Position Prev; };
typedef PtrToNode List;
typedef PtrToNode Position;
26. Implementation of Linked List
List CreateList()
{
Position TmpCell;
TmpCell=(List) malloc (sizeof(struct
Node));
if(TmpCell == NULL)
printf(" Error : Out of Space");
TmpCell->Next = NULL;
TmpCell->Prev = NULL;
return(TmpCell);
}
eatelist()
n tmpcell;
l =(struct node *)malloc(sizeof(struct
e));
cell == NULL)
" Error : Out of Space");
ell->Next = NULL;
"Link List Created Successfully...");
tmpcell);
List CreateList()
{
Position TmpCell;
TmpCell=(List) malloc (sizeof(struct
Node));
if(TmpCell == NULL)
printf(" Error : Out of Space");
TmpCell->Next = NULL;
TmpCell->Prev = NULL;
return(TmpCell);
}
eatelist()
n tmpcell;
l =(struct node *)malloc(sizeof(struct
e));
cell == NULL)
" Error : Out of Space");
ell->Next = NULL;
"Link List Created Successfully...");
tmpcell);
Implementation of Linked List
List CreateList()
{
Position TmpCell;
TmpCell=(List) malloc (sizeof(struct
Node));
if(TmpCell == NULL)
printf(" Error : Out of Space");
TmpCell->Next = NULL;
TmpCell->Prev = NULL;
return(TmpCell);
}
List CreateList()
{
Position TmpCell;
TmpCell=(List) malloc (sizeof(struct
Node));
if(TmpCell == NULL)
printf(" Error : Out of Space");
TmpCell->Next = NULL;
TmpCell->Prev = NULL;
return(TmpCell);
}
27. FIND and DELETE
on Find(ElementType X, List L)
on P; P= L->Next;
P!= NULL && P->Element != X)
->Next;
n(P);
void Delete(ElementType X, List L)
{
Position P, T;
P=Find(X,L);
T = P->Prev;
T->Next = P->Next;
if( P->Next != NULL )
P->Next->Prev = T;
free(P);
}
on Find(ElementType X, List L)
on P; P= L->Next;
P!= NULL && P->Element != X)
->Next;
n(P);
void Delete(ElementType X, List L)
{
Position P, T;
P=Find(X,L);
T = P->Prev;
T->Next = P->Next;
if( P->Next != NULL )
P->Next->Prev = T;
free(P);
}
FIND and DELETE
void Delete(ElementType X, List L)
{
Position P, T;
P=Find(X,L);
T = P->Prev;
T->Next = P->Next;
if( P->Next != NULL )
P->Next->Prev = T;
free(P);
}
void Delete(ElementType X, List L)
{
Position P, T;
P=Find(X,L);
T = P->Prev;
T->Next = P->Next;
if( P->Next != NULL )
P->Next->Prev = T;
free(P);
}
31. Implementation of Linked List
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(str
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = tmpcell;
printf("Link List Created Successfully...");
return(tmpcell);
}
eatelist()
n tmpcell;
l =(struct node *)malloc(sizeof(struct
e));
cell == NULL)
" Error : Out of Space");
ell->Next = NULL;
"Link List Created Successfully...");
tmpcell);
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(str
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = tmpcell;
printf("Link List Created Successfully...");
return(tmpcell);
}
eatelist()
n tmpcell;
l =(struct node *)malloc(sizeof(struct
e));
cell == NULL)
" Error : Out of Space");
ell->Next = NULL;
"Link List Created Successfully...");
tmpcell);
Implementation of Linked List
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(str
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = tmpcell;
printf("Link List Created Successfully...");
return(tmpcell);
}
LIST createlist()
{
position tmpcell;
tmpcell =(struct node *)malloc(sizeof(str
Node));
If(tmpcell == NULL)
printf(" Error : Out of Space");
tmpcell->Next = tmpcell;
printf("Link List Created Successfully...");
return(tmpcell);
}
32. Circular List (CREATE)
eate()
uct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &x->data);
= x;
x;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
c != 0)
struct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &y->data);
= y;
= head;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
eate()
uct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &x->data);
= x;
x;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
c != 0)
struct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &y->data);
= y;
= head;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
Circular List (CREATE)
eate()
uct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &x->data);
= x;
x;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
c != 0)
struct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &y->data);
= y;
= head;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
eate()
uct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &x->data);
= x;
x;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
c != 0)
struct node*)malloc(sizeof(struct node));
n Enter the data:");
%d", &y->data);
= y;
= head;
n If you wish to continue press 1 otherwise 0:");
%d", &c);
33. INSERT
oid ins_at_beg()
= head;
= (struct node*)malloc(sizeof(struct node));
rintf("n Enter the data:");
canf("%d", &y->data);
while (x->link != head)
= x->link;
->link = y;
->link = head;
ead = y; }
oid ins_at_beg()
= head;
= (struct node*)malloc(sizeof(struct node));
rintf("n Enter the data:");
canf("%d", &y->data);
while (x->link != head)
= x->link;
->link = y;
->link = head;
ead = y; }
INSERT
34. DELETE
del_at_beg() {
ad == NULL)
tf("n List is empty");
{
= head;
= head;
hile (x->link != head)
x = x->link;
ead = y->link; x->link = head;
free(y);
}
del_at_beg() {
ad == NULL)
tf("n List is empty");
{
= head;
= head;
hile (x->link != head)
x = x->link;
ead = y->link; x->link = head;
free(y);
}
DELETE
35. DISPLAY
oid traverse()
f (head == NULL)
printf("n List is empty");
lse
= head;
while (x->link != head)
printf("%d->", x->data); x = x->link;
printf("%d", x->data);
oid traverse()
f (head == NULL)
printf("n List is empty");
lse
= head;
while (x->link != head)
printf("%d->", x->data); x = x->link;
printf("%d", x->data);
DISPLAY