Thursday 13 October 2011

Algorithm of DLL


"various operations in Double linked list"
1)start
2)Declare3 a clasws DLL with following data.
3)Inside private: a structure node containing:
a pointer left of type node*
a ele of type integer a pointer right of type node *
Inside Public: a pointer hweadt pf type node* constructs to initialise head to NULL methods like insertbeg(),insertend(),insertmid(),delbeg().delend(),delmid(),search(),display().
4)Outside the class define insertbeg as follows read element to be inserted int and check if head=NULL,if yes do
t->left=t->right=NULL;
head=t;
else do
t->right=head;
head=t;
t->left=NULL;
5)Inside function insertend(),read element5 to be inserted iont,check if head=NULL,if Yes
t->left=t->right=NULL;
head=t;
else point p to last element,do p->right=t
t->left=p;
t->right=NULL;
6)Inside function insertmid,read elements to be inserted int,p pointing to ele where new ele has to be inserted do
t->left=p;
t->right=p->right;
p->right->left=t;
p->right=t;
7) insidefunction delbeg() do
t=head;
head=head->right;
head->left=NULL;
delete t
8)Inside Function delend() move t to the last node,then
t->left->right=NULL;
delete t;
9)In function search,traverse the linked list and displays the element found.
10)In function display,displays the whole list.
11)stop

No comments:

Post a Comment