Linked list
• A linked list is a data structure which is a sequence of nodes in
which each node is linked, or connected to, the node following it.
Each node element is called node.
In this figure store two thing :-
 An element of the list.
 A link or address of the other node.
Type of Linked List
There are 4 type of linked list such as:-
• Singly-linked list
• Doubly linked list
• Circular linked list
• Circular doubly linked list.
Operation of linked list
There are some operation to be performed on the
liked lists are as follows:-
• Creation
• Insertion
• Deletion
• traversing
• Searching
• concatenation
• Display.
Singly linked list
• A singly linked list is dynamic data structure. It may grow or shrink. Growing or shrinking
depends on the operations made.
• In ‘c’ a linked list is created using structure , pointer and dynamic memory allocation
function malloc(). We consider head as external pointer.
Creating a node:-
struct node {
Int data;
Node*next;
}
start;
Start=NULL;
Implementation of Linked List.
• Insertion of a node at the beginning
• Insertion of a node at the end
• Insertion of a node after a specified node
• Deletion of a particular node from the list
• Traversing of entire link list.
Inserting a node at beginning
• Algorithm:-
1) Insert_first(Start, item)
[Check the overflow]
if ptr=NULL, then
Print “overflow
Exit
else
Ptr=(node*)malloc(size of node));
End if
2) Set ptr->Info=item
3) Set ptr->next=start
4) Set start=ptr
Inserting a node at the end
Insert _last(Start , item)
1) [check over flow?]
if ptr=NULL, then
print ”over flow”
exit
else
ptr=(node*)malloc(sizeOf(node));
end if
2) Set ptr->info=item
3) Set ptr->next=NULL
4) If start=NULL and if then set start=p;
5) loc=start
6) Repeate step 7 until loc->next!=NULL
7) Loc=loc->next
8) Loc->next=p
Insertion at the specified position
C code:-
void insert_spe(int item, int loc){
NODE *p,*temp;
int k;
for(k=0;temp=start;k<loc;k++)
{
temp=temp->next;
If(temp==NULL){
printf(“node in the list at less than onen”);
return;
}
}
p=(NODE*)malloc(sizeof(NODE));
p->info=item;
p->next=loc->next;
loc->next=p;
}
Doubly Linked list
• In double linked list, every node has link to its previous
node and next node.
we can traverse forward by using next field and can traverse
backward by using previous field. Every node in a double
linked list contains three fields and they are shown in the
following figure...
Doubly Linked list…continue..
Structure definition Doubly linked list:-
struct node
{
int num;
struct node*prev;
struct node*node;
};
typedef struct node NODE;
Circular linked list
• Circular linked list is a sequence of elements in which every
element has link to its next element in the sequence and the
last element has a link to the first element in the sequence.
• There is no NULL at the end.
• A circular linked list can be a singly circular linked list or
doubly circular linked list.
Circular linked list… continue..
• The structure definition of the circular linked.:-
struct node
{
int info;
struct node *next;
};
typedef struct node *NODEPTR;
Circular Doubly Linked list
• Circular Doubly Linked List has properties of both doubly
linked list and circular linked list
• In which two consecutive elements are linked or connected
by previous and next pointer.
• And the last node points to first node by next pointer and also
the first node points to last node by previous pointer
Circular doubly linked list….. Conti..
•
typedef struct _dslist_node 3
{
int node_value; /* Data value */
struct _dslist_node * prev; /* pointer to previous node
*/
struct _dslist_node * next; /* pointer to next node */
}
dslist_node;
Advantages
• List can be traversed bothways from head to tail as well as tail
to head
• Being a circular linked list tail can be reached with one
operation from head node
Disadvantages
• It takes slightly extra memory in each node to accomodate
previous pointer
Practical Applications
• Managing songs playlist in media player applications
• Managing shopping cart in online shopping
Linked list using Dynamic Memory Allocation

Linked list using Dynamic Memory Allocation

  • 2.
    Linked list • Alinked list is a data structure which is a sequence of nodes in which each node is linked, or connected to, the node following it. Each node element is called node. In this figure store two thing :-  An element of the list.  A link or address of the other node.
  • 3.
    Type of LinkedList There are 4 type of linked list such as:- • Singly-linked list • Doubly linked list • Circular linked list • Circular doubly linked list.
  • 4.
    Operation of linkedlist There are some operation to be performed on the liked lists are as follows:- • Creation • Insertion • Deletion • traversing • Searching • concatenation • Display.
  • 5.
    Singly linked list •A singly linked list is dynamic data structure. It may grow or shrink. Growing or shrinking depends on the operations made. • In ‘c’ a linked list is created using structure , pointer and dynamic memory allocation function malloc(). We consider head as external pointer. Creating a node:- struct node { Int data; Node*next; } start; Start=NULL;
  • 6.
    Implementation of LinkedList. • Insertion of a node at the beginning • Insertion of a node at the end • Insertion of a node after a specified node • Deletion of a particular node from the list • Traversing of entire link list.
  • 7.
    Inserting a nodeat beginning • Algorithm:- 1) Insert_first(Start, item) [Check the overflow] if ptr=NULL, then Print “overflow Exit else Ptr=(node*)malloc(size of node)); End if 2) Set ptr->Info=item 3) Set ptr->next=start 4) Set start=ptr
  • 8.
    Inserting a nodeat the end Insert _last(Start , item) 1) [check over flow?] if ptr=NULL, then print ”over flow” exit else ptr=(node*)malloc(sizeOf(node)); end if 2) Set ptr->info=item 3) Set ptr->next=NULL 4) If start=NULL and if then set start=p; 5) loc=start 6) Repeate step 7 until loc->next!=NULL 7) Loc=loc->next 8) Loc->next=p
  • 9.
    Insertion at thespecified position C code:- void insert_spe(int item, int loc){ NODE *p,*temp; int k; for(k=0;temp=start;k<loc;k++) { temp=temp->next; If(temp==NULL){ printf(“node in the list at less than onen”); return; } } p=(NODE*)malloc(sizeof(NODE)); p->info=item; p->next=loc->next; loc->next=p; }
  • 10.
    Doubly Linked list •In double linked list, every node has link to its previous node and next node. we can traverse forward by using next field and can traverse backward by using previous field. Every node in a double linked list contains three fields and they are shown in the following figure...
  • 11.
    Doubly Linked list…continue.. Structuredefinition Doubly linked list:- struct node { int num; struct node*prev; struct node*node; }; typedef struct node NODE;
  • 12.
    Circular linked list •Circular linked list is a sequence of elements in which every element has link to its next element in the sequence and the last element has a link to the first element in the sequence. • There is no NULL at the end. • A circular linked list can be a singly circular linked list or doubly circular linked list.
  • 13.
    Circular linked list…continue.. • The structure definition of the circular linked.:- struct node { int info; struct node *next; }; typedef struct node *NODEPTR;
  • 14.
    Circular Doubly Linkedlist • Circular Doubly Linked List has properties of both doubly linked list and circular linked list • In which two consecutive elements are linked or connected by previous and next pointer. • And the last node points to first node by next pointer and also the first node points to last node by previous pointer
  • 15.
    Circular doubly linkedlist….. Conti.. • typedef struct _dslist_node 3 { int node_value; /* Data value */ struct _dslist_node * prev; /* pointer to previous node */ struct _dslist_node * next; /* pointer to next node */ } dslist_node;
  • 16.
    Advantages • List canbe traversed bothways from head to tail as well as tail to head • Being a circular linked list tail can be reached with one operation from head node Disadvantages • It takes slightly extra memory in each node to accomodate previous pointer Practical Applications • Managing songs playlist in media player applications • Managing shopping cart in online shopping