SlideShare a Scribd company logo
1 of 36
Download to read offline
Data StructuresData Structures
List
Data StructuresData Structures
List
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
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.
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,
…
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
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
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
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
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)
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.
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); } }
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
Array Implementation of List
void insert(int X,int p) //16,2
n++;
or(i=n-1;i>=p;i--)
ist[i]=list[i-1];
ist[p-1]=X;
45
void insert(int X,int p) //16,2
n++;
or(i=n-1;i>=p;i--)
ist[i]=list[i-1];
ist[p-1]=X;
Array Implementation of List
45 65 23 44
45 65 23 44 44
45 65 23 23 44
45 65 65 23 44
45 16 65 23 44
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
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
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
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
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);
}
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;
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;
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;
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 );
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;
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
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;
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);
}
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);
}
nsert(ElementType X,List L,Position P)
on TmpCell;
ell =(struct Node *)malloc(sizeof(struct Node));
pCell == NULL)
(" Error : Out of Space");
ell->Element = X;
ell->Next = P->Next ;
ext = TmpCell;
ell->Prev = P;
pCell->Next != NULL )
ell->Next->Prev = TmpCell;
nsert(ElementType X,List L,Position P)
on TmpCell;
ell =(struct Node *)malloc(sizeof(struct Node));
pCell == NULL)
(" Error : Out of Space");
ell->Element = X;
ell->Next = P->Next ;
ext = TmpCell;
ell->Prev = P;
pCell->Next != NULL )
ell->Next->Prev = TmpCell;
INSERT
DISPLAY
void PrintList(List L)
{
Position P; P=L->Next;
printf("nn List Forward :");
while(P->Next != NULL) {
printf("n %d",P->Element); P=P->Next; }
printf("n %d",P->Element);
printf("nn List backward :");
while(P != L) {
printf("n %d",P->Element); P=P->Prev; }
}
void PrintList(List L)
{
Position P; P=L->Next;
printf("nn List Forward :");
while(P->Next != NULL) {
printf("n %d",P->Element); P=P->Next; }
printf("n %d",P->Element);
printf("nn List backward :");
while(P != L) {
printf("n %d",P->Element); P=P->Prev; }
}
DISPLAY
void PrintList(List L)
{
Position P; P=L->Next;
printf("nn List Forward :");
while(P->Next != NULL) {
printf("n %d",P->Element); P=P->Next; }
printf("n %d",P->Element);
printf("nn List backward :");
while(P != L) {
printf("n %d",P->Element); P=P->Prev; }
}
void PrintList(List L)
{
Position P; P=L->Next;
printf("nn List Forward :");
while(P->Next != NULL) {
printf("n %d",P->Element); P=P->Next; }
printf("n %d",P->Element);
printf("nn List backward :");
while(P != L) {
printf("n %d",P->Element); P=P->Prev; }
}
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 element_type;
typedef struct node *node_ptr;
struct node
{
element_type element;
node_ptr next;
};
typedef node_ptr LIST;
typedef node_ptr 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 element_type;
typedef struct node *node_ptr;
struct node
{
element_type element;
node_ptr next;
};
typedef node_ptr LIST;
typedef node_ptr position;
Implementation of Linked List
struct node;
typedef int element_type;
typedef struct node *node_ptr;
struct node
{
element_type element;
node_ptr next;
};
typedef node_ptr LIST;
typedef node_ptr position;
struct node;
typedef int element_type;
typedef struct node *node_ptr;
struct node
{
element_type element;
node_ptr next;
};
typedef node_ptr LIST;
typedef node_ptr position;
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);
}
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);
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
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
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
References
www.csee.umbc.edu/courses/undergraduate/341/fall07/.../Lists/List
s1.pdf
https://courses.cs.washington.edu/courses/cse326/00wi/.../lecture1.
ppt
www.csee.umbc.edu/courses/undergraduate/341/fall07/.../Lists/List
s1.pdf
https://courses.cs.washington.edu/courses/cse326/00wi/.../lecture1.
ppt
References
www.csee.umbc.edu/courses/undergraduate/341/fall07/.../Lists/List
s1.pdf
https://courses.cs.washington.edu/courses/cse326/00wi/.../lecture1.
ppt
www.csee.umbc.edu/courses/undergraduate/341/fall07/.../Lists/List
s1.pdf
https://courses.cs.washington.edu/courses/cse326/00wi/.../lecture1.
ppt

More Related Content

What's hot

What's hot (20)

Data handling in python
Data handling in pythonData handling in python
Data handling in python
 
STL in C++
STL in C++STL in C++
STL in C++
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
DSA - Lecture 04
DSA - Lecture 04DSA - Lecture 04
DSA - Lecture 04
 
Object Class
Object ClassObject Class
Object Class
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
Generics In and Out
Generics In and OutGenerics In and Out
Generics In and Out
 
Java Tutorial Lab 9
Java Tutorial Lab 9Java Tutorial Lab 9
Java Tutorial Lab 9
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
Oop
OopOop
Oop
 
Java Tutorial Lab 7
Java Tutorial Lab 7Java Tutorial Lab 7
Java Tutorial Lab 7
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
Stl (standard template library)
Stl (standard template library)Stl (standard template library)
Stl (standard template library)
 
Csci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiCsci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iii
 
LPR - Week 1
LPR - Week 1LPR - Week 1
LPR - Week 1
 
Sets
SetsSets
Sets
 

Similar to Data structures list

Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operationsbabuk110
 
CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxOnkarModhave
 
Data structures - unit 1
Data structures - unit 1Data structures - unit 1
Data structures - unit 1SaranyaP45
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxmexiuro901
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxSaralaT3
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS Adams Sidibe
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 

Similar to Data structures list (20)

Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
 
CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptx
 
Data structures - unit 1
Data structures - unit 1Data structures - unit 1
Data structures - unit 1
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Intro ds
Intro dsIntro ds
Intro ds
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
Dsa unit 1
Dsa unit 1Dsa unit 1
Dsa unit 1
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
UNIT 3 PPT.ppt
UNIT 3 PPT.pptUNIT 3 PPT.ppt
UNIT 3 PPT.ppt
 

Recently uploaded

Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

Data structures list

  • 1. Data StructuresData Structures List Data StructuresData Structures List
  • 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
  • 13. Array Implementation of List void insert(int X,int p) //16,2 n++; or(i=n-1;i>=p;i--) ist[i]=list[i-1]; ist[p-1]=X; 45 void insert(int X,int p) //16,2 n++; or(i=n-1;i>=p;i--) ist[i]=list[i-1]; ist[p-1]=X; Array Implementation of List 45 65 23 44 45 65 23 44 44 45 65 23 23 44 45 65 65 23 44 45 16 65 23 44
  • 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); }
  • 28. nsert(ElementType X,List L,Position P) on TmpCell; ell =(struct Node *)malloc(sizeof(struct Node)); pCell == NULL) (" Error : Out of Space"); ell->Element = X; ell->Next = P->Next ; ext = TmpCell; ell->Prev = P; pCell->Next != NULL ) ell->Next->Prev = TmpCell; nsert(ElementType X,List L,Position P) on TmpCell; ell =(struct Node *)malloc(sizeof(struct Node)); pCell == NULL) (" Error : Out of Space"); ell->Element = X; ell->Next = P->Next ; ext = TmpCell; ell->Prev = P; pCell->Next != NULL ) ell->Next->Prev = TmpCell; INSERT
  • 29. DISPLAY void PrintList(List L) { Position P; P=L->Next; printf("nn List Forward :"); while(P->Next != NULL) { printf("n %d",P->Element); P=P->Next; } printf("n %d",P->Element); printf("nn List backward :"); while(P != L) { printf("n %d",P->Element); P=P->Prev; } } void PrintList(List L) { Position P; P=L->Next; printf("nn List Forward :"); while(P->Next != NULL) { printf("n %d",P->Element); P=P->Next; } printf("n %d",P->Element); printf("nn List backward :"); while(P != L) { printf("n %d",P->Element); P=P->Prev; } } DISPLAY void PrintList(List L) { Position P; P=L->Next; printf("nn List Forward :"); while(P->Next != NULL) { printf("n %d",P->Element); P=P->Next; } printf("n %d",P->Element); printf("nn List backward :"); while(P != L) { printf("n %d",P->Element); P=P->Prev; } } void PrintList(List L) { Position P; P=L->Next; printf("nn List Forward :"); while(P->Next != NULL) { printf("n %d",P->Element); P=P->Next; } printf("n %d",P->Element); printf("nn List backward :"); while(P != L) { printf("n %d",P->Element); P=P->Prev; } }
  • 30. 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 element_type; typedef struct node *node_ptr; struct node { element_type element; node_ptr next; }; typedef node_ptr LIST; typedef node_ptr 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 element_type; typedef struct node *node_ptr; struct node { element_type element; node_ptr next; }; typedef node_ptr LIST; typedef node_ptr position; Implementation of Linked List struct node; typedef int element_type; typedef struct node *node_ptr; struct node { element_type element; node_ptr next; }; typedef node_ptr LIST; typedef node_ptr position; struct node; typedef int element_type; typedef struct node *node_ptr; struct node { element_type element; node_ptr next; }; typedef node_ptr LIST; typedef node_ptr position;
  • 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