Вот что имеем
uick.java:9: error: method quicksort in class sorting cannot be applied to given types;
int[] arr0 = src.getInstance().quicksort(arr);
^
required: int[],int,int
found: int[]
reason: actual and formal argument lists differ in length
1 error
denis@denis-Aspire-V5-552G:~/proj/src$ javac Quick.java Bubble.java
Quick.java:6: error: code too large
public static void main(String[] args){
^
1 error
полностью код:
/**
* Created by denis on 27.09.15.
*/
public class sorting {
public static sorting instance;
public sorting() {
instance = this;
}
public static sorting getInstance() {
return instance;
}
//helper methods
public int[] swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
return arr;
}
public void swap(int i, int j) {
int t = fieldArray[i];
fieldArray[i] = fieldArray[j];
fieldArray[j] = t;
}
public void printarray(int[] arr){
for(int i = 0; i < arr.length; i++)
System.out.print(arr[i] + " ");
System.out.println();
}
//helper methods
public int[] bubblesort(int arr[]){
boolean p = true;
int k = 1;
while (p){
p = false;
for(int i = 0; i < arr.length - 1; i++){
if(arr[i] > arr[i+1]) {swap(arr, i, i+1); p = true;}
}
k++;
}
return arr;
}
public int[] insertionsort(int[] arr){
int temp = 0;
for(int i = 0; i < arr.length; i++)
{
temp = arr[i];
int j = i - 1;
while(j >= 0 && temp < arr[j]){
swap(arr, j + 1, j);
j--;
}
}
return arr;
}
public int[] selectsort(int[] arr){
int i, j, min, temp;
int n = arr.length;
for (i = 0; i < n - 1; i++) {
min = i;
for (j = i + 1; j < n; j++)
if (arr[j] < arr[min])
min = j;
if (min != i) {
temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
return arr;
}
public int[] shakesort(int[] arr){
int left = 0;
int rigth = arr.length - 1;
int b = 0;
while (left < rigth){
for(int i = left; i < rigth; i++){
if(arr[i] > arr[i + 1]){
b = i;
swap(arr, i, i + 1);
}
rigth = b;
}
if(left >= rigth) break;
for(int i = rigth; i < left; i--){
if(arr[i - 1] > arr[i]){
b = i;
swap(arr, i, i - 1);
}
}
left = b;
}
return arr;
}
public int[] shellsort(int[] arr){
int middle = arr.length / 2;
while (middle > 0){
for(int i = 0; i < arr.length - middle; i++){
int j = i;
while ((j >= 0) && (arr[j] > arr[j + middle])){
swap(arr, j, j + 1);
j--;
}
}
middle /= 2;
}
return arr;
}
public int[] quicksort(int[] arr, int start, int end){
int i = start;
int j = end;
int mid = arr[start + (end - start) / 2];
while (i <= j) {
while (arr[i] < mid) i++;
while (arr[j] > mid) j--;
if (i <= j) {
swap(arr, i, j);
i++;
j--;
}
}
if (start<j) quicksort(arr, start, j);
if(i<end) quicksort(arr, i, end);
return arr;
}
//pancake
public void flip(int[] arr, int m, int n){
for(int i = m; i < --n; i++){
swap(arr, i, n);
}
}
public int[] pancakesort(int[] arr){
int i, j, a, max, moves = 0;
if(arr.length < 2) return arr;
for(i = arr.length; i > 1; i--){
max = 0;
for (a = 0; a < i; a++){
if(arr[a] > arr[max]) max = a;
}
if(max == (i - 1)) continue;
if(max >= 0){
flip(arr, max, i);
moves++;
}
}
return arr;
}
//pancake
public static int[] bucketsort(int[] arr){
int max = arr[0];
for(int i = 0; i < arr.length; i++)
if(arr[i] > max)
max = arr[i];
int [] bucket=new int[max+1];
for (int i=0; i<bucket.length; i++) bucket[i]=0;
for (int i=0; i<arr.length; i++) bucket[arr[i]]++;
int pos=0;
for (int i=0; i<bucket.length; i++)
for (int j=0; j<bucket[i]; j++) arr[pos++]=i;
return arr;
}
public static int[] countsort(int[] arr){
int min = arr[0], max = arr[0];
for(int i = 0; i < arr.length; i++){
if(arr[i] > max) max = arr[i];
if(arr[i] < min) min = arr[i];
}
int[] c = new int[max - min + 1];
for(int x: arr) c[x - min]++;
int n = 0;
for(int i = 0; i < c.length; i++)
for(int j = 0; j < c[i]; j++)
arr[n++] = i + min;
return arr;
}
//heap
private static int[] fieldArray;
private static int n;
protected static int left;
protected static int right;
protected static int largest;
public void buildheap(int []arr) {
n = arr.length-1;
for(int i=n/2; i>=0; i--){
maxheap(arr,i);
}
}
public void maxheap(int[] arr, int i) {
left = 2*i;
right = 2*i+1;
if(left <= n && arr[left] > arr[i]){
largest=left;
} else {
largest=i;
}
if(right <= n && arr[right] > arr[largest]) {
largest=right;
}
if(largest!=i) {
swap(i, largest);
maxheap(arr, largest);
}
}
public int[] heapsort(int[] arr) {
fieldArray = arr;
buildheap(fieldArray);
for(int i=n; i>0; i--) {
swap(0, i);
n=n-1;
maxheap(fieldArray, 0);
}
return arr;
}
//heap
}
/**
* Created by denis on 30.09.15.
*/
public class Bubble {
public static void main(String[] args){
int[] arr = {784, 134, 319, 225, 897, 676, 596, 84, 443, 707, 109, 71, 590, 310, 431, 319, 242, 52, 786, 736, 658, 498, 466, 776, 999, 930, 337, 374, 226, 645, 752, 413, 897, 498, 44, 239, 203, 475, 349, 872, 374, 840, 257, 600, 453, 650, 176, 588, 624, 438, 568, 506, 619, 979, 201, 831, 833, 618, 323, 648, 265, 594, 379, 625, 406, 557, 733, 756, 20, 883, 11, 873, 558, 249, 691, 918, 293, 357, 14, 332, 947, 912, 397, 743, 30, 160, 895, 423, 919, 73, 637, 775, 522, 512, 526, 754, 416, 524, 470, 661, 296, 33, 505, 676, 133, 698, 966, 53, 785, 786, 78, 787, 535, 216, 140, 640, 413, 213, 558, 171, 216, 418, 329, 833, 82, 682, 916, 491, 446, 978, 539, 180, 556, 817, 427, 582, 616, 704, 581, 496, 533, 823, 36, 717, 239, 184, 976, 931, };
sorting src = new sorting();
int[] arr0 = src.getInstance().bubblesort(arr);
src.printarray(arr0);
}
}
Пользователь решил продолжить мысль 04 Октября 2015, 00:27:58:
для Bubble ошибка сохранена в том-же виде.