Linked List: by Muhammad Tasaddaq Latif
Linked List: by Muhammad Tasaddaq Latif
By
Muhammad Tasaddaq Latif
Linked List
next
Linked List
6
current
size=5
Linked List
Note some features of the list:
Need a head to point to the first node of the list.
Otherwise we wont know where the start of the
list is.
Linked List
Note some features of the list:
Need a head to point to the first node of the list.
Otherwise we wont know where the start of the
list is.
The current here is a pointer, not an index.
Linked List
Note some features of the list:
Need a head to point to the first node of the list.
Otherwise we wont know where the start of the
list is.
The current here is a pointer, not an index.
Linked List
head
2
1051
1052
1063
1053
1063
1054
1055
1051
1056
current
1057
1058
1060
1059
head
1060
1061
1062
1054
1063
1064
1057
1065
Linked List
head
2
1051
1052
1063
1053
1063
1054
1055
1051
1056
current
1057
1058
1060
1059
head
1060
1061
1062
1054
1063
1064
1057
1065
headNode
size=0
headNode
size=0
currentNode
list.add(2);
headNode
lastcurrentNode
size=1
headNode
size=0
currentNode
list.add(2);
headNode
size=1
lastcurrentNode
currentNode
list.add(6);
headNode
lastcurrentNode
size=2
lastcurrentNode
size=5
Traversing
(Traversing a Linked List) Let List be a linked list in
memory. This algorithm traverses List, applying an
operation process on each element of List. The variable
PTR points to the node currently being processed.
int data;
list* next;
}*f,*c,*p,*temp;
int t=0; //counter
void insert(void);
void print();
else {
p->next=c;
p=c;
cout<<"\n enter value";
cin>>c->data;
}//else
cout<<"\n press 1 to enter
another node ";
cin>>ch;
t++;
} //end of while
//if(ch!=1)
c->next=NULL;
temp=f;
} // end of insert
void print(void)
{
cout<<"\n value of link list
while(temp->next!=NULL)
cout<<temp->data<<" ";
temp=temp->next;
} end of while
cout<<temp->data<<" ";
}
";
{
add
add
remove
add
remove
find
add
remove
find