in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
Stack & Queue using Linked List in Data Structure
1. Presented BY : Shraddha Malviya
“Stack and Queue using Linked List”
Roll No. : MCA/25018/18
2. Stack
A stack is an ordered list with the restriction that element are
added or deleted from only one end of list termed top of stack. The
other end of the list which lies ‘inactive’ is termed bottom of stack.
3. Stack using linked list
A linked stack is a linear list of elements commonly
implemented as a singly linked list whose start
pointer perform the role of the top pointer of stack .
c b a
top
Linked representation of stack
4. Stack operation :
Push operation-
c a
top
b
Linked stack S
Push ‘d’ into S
cd ab
top
top
Push operation
PUSH_LINKSTACK(TOP,ITEM)
Call GETNODE(X)
DATA(X) = ITEM /*frame node item */
LINK(X) = TOP /* insert into x into stack */
TOP = X /*reset Top pointer */
end PUSH_LINKSTACK.
5. Pop operation-
c ab
Linked stack Stop
Pop ‘c’ from S
c ab
top
top
Push operation
POP_LINKSTACK(TOP,ITEM)
if(TOP=0)
then call LINKSTACK_EMPTY
else
{
TEMP=TOP;
ITEM=DATA(TOP);
TOP=LINK(TOP);
}
Call RETURN (TEMP)
end POP_LINKSTACK
6. Queue
A Queue is a linear list in which all insertion are
made at one end of the list known as rear or tail of
queue and all deletion are made at the other end
known as front or head of the queue . An insertion
operation is also referred to as enqueuing a queue
and deletion operation is referred to as dequeuing a
queue.
7. Queue using linked list
A linked queue is also linear list of element
commonly implemented as a singly linked list but
with two pointer ,Front and Rear . The start pointer
of the singly linked list plays the role of Front while
the pointer to the last node is set to play the role
of Rear .
a b c
front
rear
Linked representation of queue
8. Queue operation :
Insert operation--
a b
front
c
rear
Insert ‘d into queue’
a b dc
rear
front
rear
Insertion operation
INSERT_LINKQUEUE(FRONT,REAR,
ITEM)
Call GETNODE (X);
DATA (X) = ITEM;
LINK (X) = NIL;
if(FRONT = 0)
then FRONT = REAR = X;
else
{
LINK (REAR) = X;
REAR = X;
}
end INSERT_LINKQUEUE
9. Delete operation--
a b c
rear
front
Delete ‘a’ from queue
front
a b c
rear
front
Delete operation
DELETE_LINKQUEUE (FRONT , ITEM)
if(FRONT = 0)
then call LINKQUEUE_EMPTY;
else
{
TEMP = FRONT;
ITEM= DATA(TEMP);
FRONT = LINK(TEMP);
}
call RETURN (TEMP);
end DELETE_LINKQUEUE