Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Place a value on the outcomes.

Answered: 1 week ago