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.
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;
}
I need suedo code for this. Dynamic capacity Queue (Algorithm) Modify the Queue class so the...
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 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. 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 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, 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 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 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...
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,...
Haloo , i have java program , Java Program , dynamic program Given a knapsack with capacity B∈N and -n- objects with profits p0, ..., p n-1 and weights w0, ..., wn-1. It is also necessary to find a subset I ⊆ {0, ..., n-1} such that the profit of the selected objects is maximized without exceeding the capacity. However, we have another limitation: the number of objects must not exceed a given k ∈ N Example: For the items...
Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...