algorithm for queue

*enqueue operation
1.initialize the variables
rear=-1
front=-1
define maxsize
2.if rear ==maxsize-1
print (queue overflow)
exit
3.otherwise
rear++
read a data item
queue [rear ]== data
4.stop
*dequeue operation
1.if front ==-1
print (queue overflow)
exit
2.otherwise
data= queue [front]
if front == rear
{
rear=-1
front=-1
}
else
front++
3.print( the dequeue element is "data")
4.stop
 
*display operation
1.if (front= rear=-1)
print (there are ni element to display)
exit
2.otherwise
if( front=-1)
for (i =0 to rear)
else
for (i =front to rear)
print (queue[i])
3.stop

No comments