Lab1 - Sort & Search
Lab1 - Sort & Search
QUESTION 1 – SORT
Based on the following program:
import java.util.*;
}//end main
}//end class
a) Compile and run the above program. Find the output. Assume the values you are
enter: 19 30 4 8 12 9
b) Change the data type of array (refer to bold statement). Run the program using
the following input values: -
i. papaya banana apple prune orange grape
ii. 13.4 3.65 10.3 11.2 9.4 2.3
QUESTION 2 – SEARCH
Given the following algorithm for Binary Search:
FUNDAMENTAL OF DATA STRUCTURE CSC248
b) Write the function definition for the binarySearch() method (refer to the above
algorithm) to find a certain value from user input. Display the index location if the
value is found, otherwise display “Value not in list”.
c) Compile and run the program. Snap the output screen. Assume the user enter
the following values:
i. 7
ii. 15
FUNDAMENTAL OF DATA STRUCTURE CSC248
Insert the main method below into class Student and write the complete application
program for the following tasks:
a) Write the statement to display all information of the student to the screen output.
b) Write the statement to compare CGPA students and swap CGPA data between
the two elements if the CGPA for the first element is less than the CGPA for the
second element.
c) Write the statement to display student information after sorting (descending
order) and store it in an output file called output.txt.
Main method
System.out.println("\n");
catch (Exception e)
{//Catch exception if any
System.err.println("\nError: " + e.getMessage());
}
FUNDAMENTAL OF DATA STRUCTURE CSC248
finally
{
System.out.println("\nThank you.");
}
}//end main