Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sorting {
- /*
- * TODO: Implement the compare method
- */
- public static int Compare(String s1, String s2) {
- for(int i=0; i<s1.length(); i++)
- {
- char x = s1.charAt(i);
- char y = s2.charAt(i);
- int a= (int) x;
- int b= (int) y;
- if (a == b)
- {
- return 1;
- }
- }
- return 0;
- }
- /*
- * TODO: Implement the linearSearch method
- */
- /*
- * TODO: Implement the binarySearch method
- */
- public static int bubbleSort(String[] input_array) {
- // TODO implement this
- return 0;
- }
- public static int combSort(String[] input_array) {
- // TODO implement this
- return 0;
- }
- public static void plotBubbleSortTest(int N_MAX) {
- /*
- * bubble_sort_results[N] = the number of comparisons made
- * when sorting an array of size N.
- */
- int[] bubble_sort_results = new int[N_MAX];
- /*
- * For each array size between 1 (the smallest array size)
- * and N_MAX (an upper limit passed to this method), we will:
- * 1) create a random test array
- * 2) sort it, and store the number of comparisons in bubble_sort_results
- * MAKE SURE THAT YOUR METHOD IS ACTUALLY SORTING THE TEST ARRAY!!!!!!
- */
- for (int i = 1; i < N_MAX; i++) {
- String[] test_array = ArrayUtilities.getRandomNamesArray(i);
- bubble_sort_results[i] = bubbleSort(test_array);
- }
- // create a plot window
- // The argument passed to PlotWindow is the title of the window
- PlotWindow pw = new PlotWindow("Bubble Sort!");
- // add a plot to the window using our results array
- /*
- * The first argument for addPlot is a name for your data set
- * The second argument for addPlot is an array of integers,
- * In position "N" in the array, you should put the number of
- * comparisons that your algorithm made, when sorting an array
- * of size N. For example, bubble_sort_results[100] will contain
- * the number of comparisons made for sorting an array of 100 elements
- */
- pw.addPlot("BubbleSort", bubble_sort_results);
- }
- public static void plotCombSortTest(int N_MAX) {
- // the results array
- int[] comb_sort_results = new int[N_MAX];
- // test sorting for arrays from size 1 to N_MAX
- // MAKE SURE THAT YOUR METHOD IS ACTUALLY SORTING THE TEST ARRAY!!!!!!
- for (int i = 1; i < N_MAX; i++) {
- String[] test_array = ArrayUtilities.getRandomNamesArray(i);
- comb_sort_results[i] = combSort(test_array);
- }
- // create a plot window
- PlotWindow pw = new PlotWindow("Comb Sort!");
- // add a plot to the window using our results array
- pw.addPlot("CombSort", comb_sort_results);
- }
- /*
- * TODO: implement the plotCombBubble method
- * This method should plot the results from both sorting methods
- * in the same window.
- * Hint: Create a single PlotWindow, but use the addPlot method twice,
- * once for each sorting algorithm
- */
- public static void main(String[] args) {
- String s1 = "Shye";
- String s2 = "Maude";
- System.out.print(Compare(s1,s2));
- // uncomment the following lines when you want to test your sorting methods
- //plotBubbleSortTest(100);
- //plotCombSortTest(100);
- //plotCombBubble(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement