Question: write code for merge sort that does not use recursive calls to any functions. Instead, it just uses loops. Any program that can be done
write code for merge sort that does not use recursive calls to any functions. Instead, it just uses loops. Any program that can be done with recursive calls to a method can also be done without any recursive calls and still be as efficient. It saves time and space by avoiding the overhead of repeated calls to methods. Read all the details carefully and follow them.
1. First of all it has to be coded in Java and using NetBeans as IDE. (This is to simplify my task of grading them all).
2. Create new NetBeans project that is called MergeSort (case sensitive) and a main class with that same name will be created. Make sure when you create the project, the Create Main Class is checked in NetBeans and the package name is removed. i.e. mergesort.MergeSort should be changed to MergeSort before you click the Finish button.
3. The input for the program comes from a text file called input.txt and the output will be written to output.txt. Note that NetBeans requires that both those files be in the root directory of the project, namely the MergeSort folder and not the src folder or build folder that NetBeans creates.
4. The input.txt will contain several lines of numbers where each line will have integers separated by spaces as unsorted lists. Each line must be sorted separately by your algorithm. So the algorithm is called repeatedly (not recursively) for each line in the input.txt. Use Scanner inFile = new Scanner(new FileReader("input.txt"));.
5. The output.txt will have the same numbers sorted for each line and in the same order of lines as in the input file. Use PrintWriter outFile = new PrintWriter("output.txt");
6. DO NOT add any fancy code such as asking user for file names.
7. The program, using only loops must execute the merge sort algorithm by sorting smaller lists first and merging them to create bigger lists until all the numbers are sorted.
8. Programming style is important. Must have a block comment at the top of the source code file explaining in a sentence or two what the code is doing and who the author is. Then import statements, if any. Followed by class declaration and main method declaration. Rest of the code goes entirely inside the main method. Must have line comments explaining the steps and each line comment followed by the code for that step. VERY FIRST LINE COMMENT IS // Declare variables. You must also use camel case for naming variables and methods as required by Java programming style guidelines (google them).
9. Test with your own input.txt, but I will create my own input.txt to run everyone's code.
10. Zip the entire project folder into a single zip file and upload here. NOTE THAT it has to be a zip file and not some other compression format such as winzip, rar, tar etc. In windows operating system, to compress an entire folder into a zip file, you right-click the folder and select send to/compressed folder.
11. Upload the zipped folder here before Saturday, Nov 10 by midnight (end of the day). Multiple attempt till the due date are allowed.
12. DO NOT SHARE YOUR CODE WITH ANYONE. I can spot when someone copies your code and tries to slightly modify it. They will only slightly modify the code because major changes will screw up the code or even create syntax errors. (So, they would think, why take chances. Let me just rename some variables.) Whether you copy from common google source or copy from each other, all the parties involved will get a zero.
13. PROGRAM MUST RUN WITH NO SYNTAX ERRORS OR RUNTIME ERRORS IN ORDER TO RECEIVE ANY CREDIT FOR THE ASSIGNMENT.
14. Also no credit if recursive method calls are used in the code. Send me an email if you have any questions.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
