Algorithm for queue using linked list
Algorithm:
Step1: Start
Step2: Read the case in ch
Step3: Switch ch
Case1, perform enq function
Case2, perform deq function
Case3,perform display function
Case4, exit
Step4: enq function
1.read element in item
2.data[temp]=item
3.link[temp]=null
4.if rear=null,then set front=temp and rear=temp
5.else
link[rear]=temp
rear=temp
deq function
1.if front=null,then print queue is empty
2.else
Set item=data[front]
3.if front=rear,then set front=rear=null
4.else,
front=link[front]
display function
Print the elements in the queue
Step5: stop
Comments
Post a Comment