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
  • Design and implement a class Q that uses Q.java as a code base. The queue ADT...

    Design and implement a class Q that uses Q.java as a code base. The queue ADT must use class LinkedList from Oracle's Java class library and its underlying data structure (i.e. every Q object has-a (contains) class LinkedList object. class Q is not allowed to extend class LinkedList. The methods that are to be implemented are documented in Q.java. Method comment blocks are used to document the functionality of the class Q instance methods. The output of your program must...

  • Modify Algorithm 3.2 (Binomial Coefficient Using Dynamic Programming) so that it uses only a one-dimensional array...

    Modify Algorithm 3.2 (Binomial Coefficient Using Dynamic Programming) so that it uses only a one-dimensional array indexed from 0 to k. Algorithm 3.2 Binomial Coefficient Using Dynamic Programming Problem: Compute the binomial coefficient. Inputs: nonnegative integers n and k, where ks n. Outputs: bin2, the binomial coefficient (2) int bin2 (int n, int k) index i, j; int B[0..n][0..k]; for (i = 0; i <= n; i++) for (i = 0; j <= minimum( i,); ++) if (j == 0...

  • CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....

    CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...

  • Describe in pseudo-code a linear-time algorithm for reversing a queue Q. To access the queue, you...

    Describe in pseudo-code a linear-time algorithm for reversing a queue Q. To access the queue, you are only allowed to use the methods of a queue ADT. Hint: Consider using an auxiliary data structure.

  • I need a method that takes two parameters, one is Queue and other is int n,...

    I need a method that takes two parameters, one is Queue and other is int n, then I want to use stack and/or queue to reverse the order of n elments in Queue instance. I don't want to use recursion. I want the reverse class with method taking queue and n as parameters and a main method. I want stack class with array implementation with push and pop methods and Queue class with linkedlist implementation with methods deQueue and enQueue...

  • Assume a dynamic queue which is serviced by a Priority Based Round Robin algorithm such that ther...

    Assume a dynamic queue which is serviced by a Priority Based Round Robin algorithm such that there exists three priorities (1,2,3) which are used as multipliers of the basic time quantum value with the resulting number being the maximum service time the corresponding job will receive each time it gets the CPU. For a maximum amount of time equal to 1 basic time quantum , a priority 2 job gets the CPU for the maximum amount of time equal to...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

  • Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h>...

    Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h> #include <stdlib.h> #define SIZE 5 void displayData(int [], int s); void getData(int array[], int size) {     for(int i=0; i<SIZE; i++)     {         scanf("%d", &array[i]);     } } int main() {     int grades[SIZE];     for(int i=0; i<SIZE; i++)     {         grades[i] = 0;     }     getData(grades,SIZE);     displayData(grades, SIZE); } void displayData(int grades[], int size) {     for(int i=0; i<size;...

  • i need the sloution with java code please :) Using your Queue class write a GUI...

    i need the sloution with java code please :) Using your Queue class write a GUI program that opens a file contains integers in the range [0 .. 999] "in.txt". The program stops reading if -1 is read. Your program should use queues to make the output such that the first textfield output contains the integers in the range 0..9 but in their same order as in the input, the same for the second textfield but in the range 10..19,...

  • Reimpliment this bottom-up merge-sort queue code so it does not rely on the "import edu.princeton.cs.algs4.StdRandom" and...

    Reimpliment this bottom-up merge-sort queue code so it does not rely on the "import edu.princeton.cs.algs4.StdRandom" and "import edu.princeton.cs.algs4.StdOut"imports: /* import java.util.Queue; import java.util.LinkedList; import edu.princeton.cs.algs4.StdRandom; import edu.princeton.cs.algs4.StdOut; public class BottomUpMergeSort { public static void main(String[] args) { int N=Integer.parseInt(args[0]); Double [] a = new Double [N]; for(int i=0;i<N;i++) {    a[i]=StdRandom.uniform();    } StdOut.println("Unsorted"); printArr(a); Queue que=sort(a); StdOut.println("\nSorted"); BottomUpMergeSort.printQue(que); } public static Queue sort(Double[] a) {    int N=a.length;       Queue->ques=new LinkedList>();       for(int i=0;i<N;i++) {       ...

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