Question

I need suedo code for this. Dynamic capacity Queue (Algorithm) Modify the Queue class so the...

I need suedo code for this.

Dynamic capacity Queue (Algorithm) Modify the Queue class so the queue size will be dynamic, once you use 3/4 of queue you double the size once you use only 1/4 of queue you change the queue size to half.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Psuedocode:
Queue =[]
capacity = //set by user
currentSize=0;
front=0;
rear=-1;
//method to add to queue
Enqueue(item)
{
   if(checkQuaterFull())
   DoubleCapacity();
   else
   {
   rear++;
   if(rear==capacity-1)
   rear=0;
   Queue[rear]=item;
   currentSize+=1;
   }
  
}
//to check list is 3/4 full or not
bool checkQuaterFull()
{
   if((3/4)*capacity <=currentSize)
   return true;
   return false;
}
//to double the capacity of list
DoubleCapacity()
{
   A[] = new array with double capacity;
   Copy(Queue,A);//copying contents of Queue to A
   Queue =A;
   update new capacity;
}
//method to dequeue from queue
Dequeue()
{
   if(checkQuaterEmpty())
   HalfCapacity();
   else
   {
       front++;
       if(front == capacity-1)front=0;
       currentSize--;      
   }
}
bool checkQuaterEmpty()
{
       if(currentSize<=(1/4)*capacity )
   return true;
   return false;
}
HalfCapacity()
{
   A[] = new array with half capacity;
   Copy(Queue,A);//copying contents of Queue to A
   Queue =A;
   update new capacity;
}

Add a comment
Know the answer?
Add Answer to:
I need suedo code for this. Dynamic capacity Queue (Algorithm) Modify the Queue class so the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT