You are required, but not limited, to turn in the following source files:
Assignment11.java (You do not need to modify this file.)
StackRearranger.java — complete this file.
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Stacks
Class Diagram:

Assignment #11 will be the construction of a program that rearranges the content of a stack into a sorted order using other stacks.
Your program needs to read in numbers and push them into the stack called initialStack.
A user will specify how many number will be entered, and the numbers will be distinct numbers from 1 to some positive number.
For instance, if a user specifies that 7 numbers will be entered, then the numbers to be inserted into the initial stack will be: 1, 2, 3, 4, 5, 6, 7 (i.e., 1 through 7), but they might not be in any sorted order, for instance, 3, 6, 4, 7, 1, 2, 5.
Then your program should remove each element from the initialStack from its top one by one, and the objective is to insert all numbers into the stack called outputStack in the increasing order.
If the top number of the initial stack is 1, then you can push 1 into the output stack. However, it is some other larger number, then it needs to wait to be pushed into the output stack until all numbers that are smaller than that number are already pushed into the output stack.
Here, we will be using other stacks called holdingStacks. The number of such holding stacks will be specified by a user as well and it will be an array of Stack objects.
If there is a number larger than 1, then you need to push it onto one of the holding stacks, but here is the condition:
-Check each holding stack in its increasing index order, if one is empty or the number to be pushed is smaller than the top element of the holding stack, then you can push the number onto such holding stack. This holding stack is called bestStack for the number.
-If you cannot find such holding stack, then it means that you cannot complete this rearrangement task. It should stop and return false.
Once the number 1 is stored in the output stack, then you need to keep checking if the top number of the initial stack is 2, or the top of any holding stack is 2. If the top number of the initial stack is 2, then you can push it onto the output stack. If the top of any holding stack is 2, then pop it, and push it onto the output stack.
After this, you need to keep looking for the next number 3, and so on until the largest number is pushed onto the output stack.
Here is an example. Suppose that you are given the following sequence of numbers:
7 9 1 2 5 6 8 4 3
with three holding stacks #0, #1, and #2.
The top of the initial stack is 3, if you pushed all numbers from left to right onto the initial stack. Since it is not the smallest, you need to push 3 onto the holding stack, say, #0.
The next number of the initial stack is 4. It cannot be pushed onto the holding stack #0 because it is larger than the top of the holding stack #0, which is 3. So we can push 4 onto another holding stack, say #1.
Similarly, 8 will be pushed onto the holding stack #2.
Now, the next number 6 can be pushed only onto the holding stack #2 because that is the only stack whose top is larger than 6. Remember, the content of each holding stack needs to be increasing order.
After pushing 3, 4, 8, 6, 5, 2 onto holding stacks, the content of holding stacks will be:
Holding Stack 0: [3, 2]
Holding Stack 1: [4]
Holding Stack 2: [8, 6, 5]
The next number from the initial stack is 1, so this is pushed directly onto the output stack.
At this point, the next smallest number 2 is at the top of the holding stack #0. So we pop it and push it onto the output stack. Then we will do the same for the number 3. We continue to pop from the holding stacks as long as the next smallest number is at the top of one of the holding stacks.
After popping 2, 3, 4, 5, and 6, we have:
Holding Stack 0: []
Holding Stack 1: []
Holding Stack 2: [8]
The next smallest number 7 is not in the holding stacks, so we need to re-start popping numbers from the initial stack which still contains: [7, 9].
This class displays a menu for the Stack Rearranging. If a user enters “E”, then it asks to enter a size of the initial stack and also a number of holding stacks, then it will display a result for the problem. This class is given by the instructor.
The StackRearranger class contains a constructor to set up an initial configuration.
It also contains methods to print out stacks as well as to rearrange stack content.
You need to complete the following methods.
Please see the StackRearranger.java for more details.
There are 6 portions where you need to complete the code.
Please look for the line such as:
/****1. ADD Your Code Here ****/
since that is where you need to add more code.
public boolean rearrange()
You need to write the rearrange method that rearranges the initial stack and also determines if it is feasible. It should return true if a rearrangement is successful, false otherwise.
Please see the StackRearranger.java file for more details.
public void fromHoldingStackToOutputStack()
You need to write the fromHoldingStackToOutputStack method that moves the smallest element among all holding stacks into the output stack.
It also keeps track of the next smallest number and the holding stack that contains in it using the variable smallestNumber and stackWithNextSmallest.
Please see the StackRearranger.java file for more details.
public boolean putInHoldingStack(int number)
You need to write the putInHoldingStack method that tries to push the parameter number into the best stack, i.e., the one with the top element larger than the parameternumber and also with the top element smallest among such holding stacks.
If it cannot find such holding stack, it should return false. It should return true otherwise return true.
Please see the StackRearranger.java file for more details.
Requirements:
You need to implement this method using an object of the Stack class in java.util package.
The following files are the test cases that will be used as input for your program (Right-click and use “Save As”):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use “Save As”):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
OR you can download all files at once:
Your program is expected to be robust enough to pass all test cases. You may use the Scanner class, but are not limited to it, to handle your user input.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
Custom Writings Help is a Quality-Oriented Company in Online Writing as a result of hiring exceptional professionals to execute clients' tasks.
Essays
At Custom Writings Help,We understand the struggle of research paper writing, and that is why at Custom WritingS Help, we are all out to help you. We pride ourselves on having a team of clinical writers. The stringent and rigorous vetting process ensures that only the 'BEST' Writers are chosen for the job. We have highly qualified Ph.D. and MA writers working with us; we equally offer these experienced writers specific bonuses and incentives to make them deliver highly original, unique, and informative content at reasonably low prices.
Admissions
Thesis Writing Service
Worlwide, Many Masters Students are struggling with Thesis Completion. A thesis is likely to be the longest and most challenging piece of work a student has ever completed. However, unlike essays and other assignments, a student can pick a particular interest topic and work on their initiative. Fortunately, we are there for you. At Custom Writings Help, you are assured of an authentic, imaginative, informative, linguistically great, and advantageous thesis that adheres to all your needs. So, why continue considering different writers when you have discovered the best in the field?
Editing
Custom Papers
Not a single student can avoid writing custom papers. However, a total lack of experience, skills, and time makes it very hard to produce a superb writing piece. Therefore, if you are seeking professional help, turn to us. Our specialized and experienced writers compose a variety of model papers, including custom essays, college term papers, research papers, book reports, MBA essays, executive summaries, dissertations, Ph.D. theses, admission essays, and research proposals for college and university students at any level.
Coursework
Essay Writing
Most of the students disregard the critical principles of essay writing and compose papers below sensible guidelines. Therefore, with Custom Writings Help, one should not worry about his/her essay. Our Writers compose informative and engaging content on all complexities and topics. We write meaningful and smart essays while prioritizing all aspects that bring about a good grade, such as impeccable grammar, proper structure, zero-plagiarism, and conformance to guidelines.
Coursework
Coourse Work Writing
Don't let the seemingly never-ending onslaught of writing assignments get you down. If you are looking where to get course work assistance online, the writers at Custom Writings Help are here to assist you with all of your writing needs. We undertake to unique delivery of papers that meet the professor's requirements. The content is proofread, edited, and checked plagiarism before submission to customers. No matter how big or small your work is, we will deliver on time. Try US Now! !
Coursework
Dissertation Writing Service
High-Quality Dissertation Writing Services are rare. They require Ph.D. academicians – not easily found. However, are an exception. The years, time, and resources we have invested in the dissertation world has given us a competitive advantage over others. Choose to come to Custom Writings Help; You will find perfect Ph.D. consultants who have written hundreds of dissertations theses ready to help you. Let our dissertation-writing services help you craft your dissertation, for you are assured we will give you the results.