From 10570c2d17aeb5d8a65947808750bbd3b7886645 Mon Sep 17 00:00:00 2001 From: patel-nikhil Date: Sat, 25 Jan 2020 23:21:56 -0500 Subject: [PATCH] Made heapsort methods static. Reorganized Example_v0 --- Example_v0.java | 4 +--- HeapSort.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Example_v0.java b/Example_v0.java index 8d5507a..08ebbd1 100644 --- a/Example_v0.java +++ b/Example_v0.java @@ -1,6 +1,4 @@ -package controller; - -import java.util.Random; +package sample; public class A { private static int Z; diff --git a/HeapSort.java b/HeapSort.java index 3669df3..e7da94b 100644 --- a/HeapSort.java +++ b/HeapSort.java @@ -14,7 +14,7 @@ public class Heap { * @param y associated array * @param n problem size */ - public void sortHeap (String[] x, String[] y, int n ) { + public static void sortHeap (String[] x, String[] y, int n ) { this.construct(x,y,n); this.sort(x,y,n); } @@ -25,7 +25,7 @@ public void sortHeap (String[] x, String[] y, int n ) { * @param y associated array * @param n problem size */ - public void sortHeap (String[] x, Integer[] y, int n ) { + public static void sortHeap (String[] x, Integer[] y, int n ) { this.construct(x,y,n); this.sort(x,y,n); } @@ -36,7 +36,7 @@ public void sortHeap (String[] x, Integer[] y, int n ) { * @param y associated array * @param n problem size */ - private void construct(String[] x, String[] y, int n){ + private static void construct(String[] x, String[] y, int n){ for (int i = (n-1)/2; i >= 0; i--){ int index = i; @@ -65,7 +65,7 @@ private void construct(String[] x, String[] y, int n){ * @param y associated array * @param n problem size */ - private void construct(String[] x, Integer[] y, int n){ + private static void construct(String[] x, Integer[] y, int n){ for (int i = (n-1)/2; i >= 0; i--){ int index = i; @@ -94,7 +94,7 @@ private void construct(String[] x, Integer[] y, int n){ * @param y associated array * @param n size of input array */ - private void sort(String[] x, String[] y, int n){ + private static void sort(String[] x, String[] y, int n){ int end = n - 1; while (end > 0){ @@ -128,7 +128,7 @@ private void sort(String[] x, String[] y, int n){ * @param y associated array * @param n size of input array */ - private void sort(String[] x, Integer[] y, int n){ + private static void sort(String[] x, Integer[] y, int n){ int end = n - 1; while (end > 0){ @@ -156,7 +156,7 @@ private void sort(String[] x, Integer[] y, int n){ } } - private String lower(String str){ + private static String lower(String str){ String lowercase = ""; for (int i = 0; i < str.length(); i++){ lowercase += java.lang.Character.toLowerCase(str.charAt(i)); @@ -172,7 +172,7 @@ private String lower(String str){ * @param a index of first element * @param b index of second element */ - private void exchange(Comparable[] x, Comparable[] y, int a, int b){ + private static void exchange(Comparable[] x, Comparable[] y, int a, int b){ Comparable temp = x[a]; x[a] = x[b]; x[b] = temp; @@ -188,7 +188,7 @@ private void exchange(Comparable[] x, Comparable[] y, int a, int b){ * @param n length of array * @return true if sorted, otherwise false */ - private boolean isSorted(String[] x, int n){ + private static boolean isSorted(String[] x, int n){ for (int i = 0; i < n - 1; i++){ if (lower(x[i]).compareTo(lower(x[i+1])) > 0) { return false;