Animation. Outline Key frame animation Hierarchical animation Inverse kinematics.
Linked list without animation
-
Upload
lovelyn-rose -
Category
Education
-
view
1.496 -
download
1
description
Transcript of Linked list without animation
Dr. S. Lovelyn Rose
PSG College of Technology
NL I TK E D LI S
SINGLY LINKED LIST
DOUBLY LINKED LIST
Previous node Data part Next
node
NODE STRUCTURE
DATAADDRES
S
Data 1 Data 2 . . . . . . Data n
ADDRESS
ADDRESS
Data 1 Data 2 . . . . . Data n
ADDRESS
Singly Linked List
ID Name Desig Address of Node2 ID Name Desig Address of Node 3 ID Name Desig NULL
Start
Doubly Linked List
NULL Data 1 Address of Node 2Address of Data 2 Address of Node 1 Node 3Address of Data 3 Node 2 NULL
Start
CIRCULAR LINKED LISTSINGLY
Node 1 Node 2 Node 3
DOUBLY
Node 1 Node 2
Node 3
Start
Data 1 Node 2
Data 2 Node 3
Data 3 Node1
Start
Node3 Data 1 Node 2
Node 1 Data 1 Node 3
Node 2 Data 1 Node1
struct node{
int x; char c[10];struct node *next;}*current;
Node Structure
x c[10] next
create_node(){ current=(struct node *)malloc(sizeof(struct
node)); current->x=10; current->c=“try”; current-
>next=null; return current;}Allocation
Assignment
Node Creation
x c[10] next
10 try NULL
Create a linked list for maintaining the employee details such as Ename,Eid,Edesig.
Steps:1)Identify the node structure2)Allocate space for the node3)Insert the node in the list
Inserting N Nodes
EID EName EDesig
struct node
{
int Eid;
char Ename[10],Edesig[10];
struct node *next;
} *current;
next
Insert_N_Nodes(N){
Start=current=create_node();
AlgorithmNumber of nodes
Allocation and Assignment
011 ABI HR
Start, current
NULL
for(i=1;i<n-1;i++){
current->next=create_node();current=current->next;
}}
011 ABI HR
Start, current
012 Banu DBAi=1 NULL
Insert(){
c=create_node();start=c;c1=create_node();c->next=c1;c2=create_node();c1->next=c2;
}
Inserting 2 nodes
10 c
20 c1
30 c2
start
Insert_a_node(Start){current= create_node();current->next=Start;Start=current;}
Note : Passing Start as a parameter implies the list already exists
Insertion at the first positionStart
20 30
10Start
20
30
10
current
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’
Insertion at the middle
Start
10 20 30 40
25
Use two pointers namely, fast and slowMove the ‘slow’ pointer by one element in the
listFor every single movement of ‘slow’, move
‘fast’ by 2 elementsWhen ‘fast’ points to the last element, ‘slow’
would be pointing to the middle elementThis required moving through the list only
onceSo the middle element is found in a time
complexity of O(n)
Finding the middle element of alinked list in O(n) time complexity
{current=(struct node *)malloc(sizeof(struct node))fast=slow=Startdo{
if(fast->next->next!=null)fast=fast->next->next
else break;slow=slow->next
}while(fast->next!=null)current->next=slow->nextslow->next=current}Note : fast and slow are below the node they point to
Insert_Middle(Start)
Start 10
20
30
40
25
fast slow
current
Insert_last(Start){
current=Start;while(current->next!=null){
current=current->next;}temp=create_node();current->next=temp;
}
Insertion at the last
Start 10
20
30
40
25
temp
delete_node(start,x){
temp=start;temp1=temp;while(temp!=null){if(temp->n==x){if(temp==start && temp->next==null)
start=null
Delete a node with a value x
Last node
Only one nodestart
10
temp
else if(temp==start){
start=start->next;temp->next=null;break;
}else if(temp->next==null){
temp1->next=null;}
Cont..
First node
start
10 temp
20
Last node
start
10
20
temp1
temp
else{
temp1->next=temp->next;temp->next=null;break;
}}temp1=temp;temp=temp->next;}}
Cont..
Any node
Start 50
20
10
40
temp1
temp
Inserting N nodesInsert_node(N){start=c=create_node();for(i=0;i<N-1;i++){
c1=create_node();c->next=c1;c1->previous=c;
}}
Doubly Linked List
create_node(){c=(struct node*)malloc(sizeof(struct
node)) c->x;
c->previous=null;c->next=null;return c;
}
10
cstart
20
c1
delete_node(start,n){temp=startwhile(temp!=null){if(temp->x==n){ if(temp==start) {temp->next->previous=null;start=temp->next}
Node Deletion
End of list
single node
10
temp
start
else if(temp->next==null) temp->previous->next=null;else{temp->next->previous=temp->previous;temp->previous->next=temp->next;}}else temp=temp->next;}if(temp==null) print(“Element not found”);}
Last node
20
start
10
temp
middle node
30
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/
To View With Animation