CLL
CLL
• Stack implementation array drawback is we need to know size in advance.if the size is
fixed we cannot increase or decrease size.
• Stack full condition doesn’t arise in linked stacks.
Node representation
Struct node
{
int data;
struct node *next;
}*new,*tos,*temp;
New-allocation of memory
Tos-top of stack
Temp-traversing
PUSH
new=(struct node*)malloc(sizeof(struct node);
Printf(“enter a value”);
scanf(“%d”,&value);
new->data=value;
new->next=NULL;
if(toss==NULL)
tos=new;
else
{
new->next=tos;
tos=new;
}
POP
if(tos==NULL)
printf(“stack is empty”);
else
temp=tos;
Printf”deleted item is %d”,tos->data);
tos=tos->next;
temp->next=NULL;
free(temp);
PEEK(DISPALYING TOP MOST)
if(tos==NULL)
{ printf(“stack is empty”);
}
else
{
printf(“top most element is %d”,tos->data);
}
DISPLAYING
TEMP=TOS;
if(tos==NULL)
{ printf(“stack is empty”);
}
else
while(temp!=NULL)
{
printf(“%d->”,temp->data);
temp=temp->next;
}
}
Linked queues
• Drawback with respect to array implementation of queue is we must know the size
in advance.
• we are using single linked list to implement to queue in order to overcome this
drawback.
• Node representation
Node representation
Struct node
{
int data;
struct node *next;
}*new,*front,*rear,*front;
Linked queues operations