Thursday 13 October 2011

Algorithm of CLL


"various operations in Cirular linked list"

1)start
2)Declare a class cll with the following data
3)Inside private:declare a  structure node,containing a pointer link of type node* and a ele of type integer.
4)Inside public:declare a constructor to initialise Head to NULL and declare functions insertbeg(),insertend(),insertmid(),delbeg,delend().delmid(),findmax(),findmin() and display.
5)Outside the class define insertbeg().Element to be inserted is stored in t.check whether head is equal to NULL,If yes do head=t;
t->link=head;
else store last node address in p and do
t->link=head;
head=t;
p->link=head;
6)Inside function insertend() read the node to be inserted int and last node address in p.If head=NULL do head=t,t->link=head.
else do p->link=t;
t->link=head.
7)In function delmid() store new node address in t and node after which new node is to be inserted in p and do
t=p->link;
p->link=t->link;
8)In function delbeg(),check if head=NULL,if Yes Print"list is empty" else check if p->link=head if yes delete p,head=NULL,
else store last node address in p.do p->link=head->link;
p=head;
head=head->link;
delete p;
9)In function delend() check if head=NULL,If Yes print"list is empty" else check if p->link=head, if yes delete p,
Head=NULL;
else t=p->link,p->link=head,delete t.
10)In function delmid(),stotre address of node before node to be deleted in p,do
t=p->link,
p->link=t->link,
delet t.
11)In function findmax(),return the maximum element in list.
12)In function findmin(),return the minimum element in list.
13)In function display,displays the list.
14)Stop



No comments:

Post a Comment