Question: Starter File: Lab3.java and L3input.txt (both files are at the bottom) Execute your solution like this. C:> java Lab3 L3input.txt Background You will fill in

Starter File: Lab3.java and L3input.txt (both files are at the bottom)

Execute your solution like this. C:\> java Lab3 L3input.txt

Background

You will fill in the code for method insertInOrder and the upSize() method at the bottom of your starter file. Main is written for you. Every time you read another number from the input file, you will pass that new value into insertInOrder. It will place the new number into the array in it's sorted place. To figure out where the new number belongs you must compare it to the last number in the array. If the new value is smaller than that element, the end element must move up one to the right. You then keep moving toward the front of the array one step at a time comparing the new value to the next element. If the new value is smaller than it, you must push that element up one place. You keep doing this until the new value is not smaller than the one you are comparing it to. At this point you can now copy the new value into the hole you just opened up in the array.

At no time is the array allowed to be in un-sorted order. You are not allowed to copy the new value into the array except the one time when you copy it into its proper sorted place. You are not allowed to create another array. You are not allowed to just fill up the array and then call Arrays.sort() or write some sorting loop on it after it's full. The array must be in sorted order at all times.

CORRECT OUTPUT

Lab3.java:

/* Lab3.java InsertInOrder */ import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length  java Lab3 L3input.txt "); System.exit(0); } // LOAD FILE INTO ARR USING INSERINORDER Scanner infile = new Scanner( new File( args[0] ) ); //  

L3input.txt:

31 145 70 5 27 103 71 140 8 162 98 153 8 109 103 31 145 157 27 90 75 19 23 25 69 
Command Prompt C: \Users\tim\Desktop\lab-03 solutions>javac Lab3.java C: \Users\tim\Desktopl\lab-03\solutions>java Lab3 L3input.txt SORTED ARRAY: 5 8 8 19 23 25 27 27 31 31 69 70 71 75 90 98 103 103 109 140 145 145 153 157 162 25 2 27 32 3 70 72 75 9e 98 10 C:\Users tim\Desktop\lab-03 solutions>

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!