Thursday 13 October 2011

Algorithm of SLL


"various operations in Single linked list"

1)start
2)define a class sll with a structure node having one integer ele and one self referencing structure variable link,under private section.
3)under public,define a variale head of type node *, a construction for initialising head to NULL and methods like insertbeg(),insertend(),insertmid(),delbeg(),delend(),delmid(),findmax(),findmin().display().
4)outside the class define the function insertbeg() enter element to be inserted and check whether head=NULL.if yes do
t->link=NULL;
head=t;
or else do
t->link=head;
head=t;
5)define the function insert end as follows
if head=NULL do
t->link=NULL;
headt=t;
else take a pointer of type node*,p and make it point to the last ele.Now do
p->link=t;
t->link=NULL;
6)define function insertmid() as follows read the element after which new element has to that element.Now do
t->link=p->link;
p->link=t;
7)define function delbeg() as follows
make pointer t to point to the last but one elements then do
p=t->link;
t->link=NULL;
delete p;
9)Define function delmid as follows.
if t is pointing to ele to be deleted,do
p=t->link;
t->link=p->link;
delete p;
10)In function findmax(),find maximum element and display
11)In function findmin(),finf minimum element and display
12)In function display,displays all elements
13)stop

No comments:

Post a Comment