Question: Write a java program to read in a set of numbers and perform a MergeSort to arrange the numbers in ascending order. Your program is

Write a java program to read in a set of numbers and perform a MergeSort to arrange the numbers in ascending order. Your program is expected to use queues to keep track of the ascending runs in the numbers, which are portions that are already in order.
Consider the list 4 7 9 2 8 6 1 5 3. A run is a
sequence of consecutive items on a list that are already
in order. The list shown above has five runs:
first run: 4 7 9
second run: 2 8
third run: 6
fourth run: 1 5
fifth run: 3
Remember: You must create a number queue to do mergeSort not arrays. It has to be Queues!
Down below is some code that can be used
public class NumberQueue {
public static final int MAXSIZE=100;
public int getQsize() {
return (MAXSIZE+lastLoc-firstLoc) % MAXSIZE;
}
public boolean fullCheck() {
return (getQsize() == MAXSIZE-1);
}
public boolean emptyCheck() {
return (getQsize() == 0);
}
public int runCount(mergeSort Q)
{
int count=1;
int prior=-9999;
for(int i=0; i
{
if(Q.front()
{
count++;
prior=Q.front();
Q.insert(Q.front());
Q.remove();
}
}
return count;
}
public int insert(int val) {
if (fullCheck()) return -1;
else {
numArray[lastLoc] = val;
lastLoc = (lastLoc +1) % MAXSIZE;
return 0;
}
}
public int front() {
return numArray[firstLoc];
}
public void remove() {
if (!emptyCheck()) firstLoc = (firstLoc +1) % MAXSIZE;
}
private int firstLoc=0;
private int lastLoc=0;
private int[] numArray = new int[MAXSIZE];
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!