1. L I N K E D L IST
Dr. S. Lovelyn Rose
PSG College of Technology
2. SINGLY LINKED LIST
DATA ADDRESS
Data 1 Data 2 . . . . . . Data n ADDRESS
DOUBLY LINKED LIST
ADDRESS Data 1 Data 2 . . . . . Data n ADDRESS
Previous node Data part Next node
3. Start ID Name Desig Address
of Node2
ID Name Desig Address of
Node 3
ID Name Desig NULL
4. Start NULL Data 1 Address of
Node 2
Address of Data 2 Address of
Node 1 Node 3
Address of Data 3
Node 2 NULL
5. CIRCULAR LINKED LIST
SINGLY
Start
Data 1 Node 2 Data 2 Node 3 Data 3 Node1
Node 1 Node 2 Node 3
DOUBLY
Start
Node3 Data 1 Node 2 Node 1 Data 1 Node 3
Node 1 Node 2 Node 2 Data 1 Node1
Node 3
6. struct node
{
int x;
x c[10] next
char c[10];
struct node *next;
}*current;
8. Create a linked list for maintaining the employee details
such as Ename,Eid,Edesig.
Steps:
1)Identify the node structure struct node
{
2)Allocate space for the node
int Eid;
3)Insert the node in the list char Ename[10],Edesig[10];
struct node *next;
} *current;
EID EName EDesig next
9. Number of nodes
Allocation
Insert_N_Nodes(N)
and
{ Assignment
Start=current=create_node();
Start,
current
011 ABI HR NULL
10. for(i=1;i<n-1;i++)
{
current->next=create_node();
current=current->next;
} }
Start,
current
011 ABI HR
i=1 012 Banu DBA NULL
12. Start
20 30
Insert_a_node(Start)
{ Start
current= create_node(); 10
current->next=Start; 20
Start=current;
} current 30
10
Note : Passing Start as a parameter implies the list already exists
13. Start
10 20 30 40
25
Steps:
1)Have a pointer (slow) to the node after which the new
node is to be inserted
2)Create the new node to be inserted and store the address
in ‘current’
3) Adjust the pointers of ‘slow’ and ‘current’
14. Use two pointers namely, fast and slow
Move the ‘slow’ pointer by one element in the list
For every single movement of ‘slow’, move ‘fast’ by 2
elements
When ‘fast’ points to the last element, ‘slow’ would be
pointing to the middle element
This required moving through the list only once
So the middle element is found in a time complexity of
O(n)
15. {
current=(struct node *)malloc(sizeof(struct node))
fast=slow=Start Start 10
do
fast slow
{
if(fast->next->next!=null) 20
fast=fast->next->next current
else break;
slow=slow->next 25 30
}while(fast->next!=null)
current->next=slow->next
slow->next=current 40
}
Note : fast and slow are below the node they point to
23. Download the file from
http://www.slideshare.net/lovelynrose/linked-list-17752737
Also visit my blogs :
http://datastructuresinterview.blogspot.in/
http://talkcoimbatore.blogspot.in/
http://simpletechnical.blogspot.in/