java - I'm in the process of writing a Merge Sort program, I'm getting the following errors: -


please consider following code:

public class mergesort {     public static void main(string[] args) {              int[] = new int[10];                  // printing initial arrays                      system.out.println("array elements before sorting follows:");                         for(int = 0;i < a.length;i++){                          system.out.println(a[i] + " ");                                                       }                          // call mergesort method here                           // printing sorted array here                      system.out.println("sorted array follows:");                      //for(int j = 0;j < result.length;i++){                      //system.out.println(result[i] + " ");                     //}       public static int[] merge_sort(int[] b){          if(b.length <=1){              return b;          }          int midpoint = b.length/2;          int[] left = new int[midpoint];          int[] right;          if(b.length % 2 == 0){              right = new int[midpoint];          }else {             right = new int[midpoint+1];                }          // array store result          int[] result = new int[b.length];          // populating array in left array          (int = 0; < midpoint; i++){              left[i] = b[i];          }          // populating in right array         int x = 0;         (int j=midpoint;j<b.length;j++){              right[x] = b[j];             x++;         }          // using recursion divide array in left , right again , again          left = merge_sort(left);         right = merge_sort(right);       }// end of method merge_sort     }// end main method     }// end of class mergesort 

i'm getting following error on following lines in eclipse: cross sign indicates error points in eclipse:

x public static int[] merge_sort(int[] b){

error says: illegal modifier parameter merge_sort; final permitted.

x return b;

error says: void method cannot return values. have defined method return type integer array why i'm getting error?

x left = merge_sort(left); x right = merge_sort(right);

error says: method merge sort undefined type mergesort

i think if fix indentation in code problem obvious. merge_sort method declared inside main method.

just move }// end main method closing brace onto line above declare merge_sort , should compile ok.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -