Results 1 to 4 of 4

Thread: Merge sort

  1. #1
    Aivy is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Merge sort

    anybody here can help me with this i always got this error
    'class' or 'interface' expected on line 40
    please help me


    public class MergeSort1 {
    public static void main (String []args){
    int ctr1=1;ctr2=1;ctr3=1;
    int N1=4;N2=3;

    String array1[]={"Dopey","Grumpy","Happy","Sleepy"};
    String array2[]={"Bushful","Doc","Sneezy"};
    String array3[]=new String[7];

    while ((ctr1<=N1) || (ctr2<=N2))
    {

    if(ctr1>N1)
    {
    copyArr2();
    }
    else
    {
    if(ctr2>N2)
    {
    copyArr1();
    }
    else
    {
    if(Arr1[ctr1]<Arr2[ctr2])
    {
    copyArr1();
    }
    else
    {
    copyArr2();
    }
    }
    }
    ctr3++;
    }
    }
    }
    public String copyArr1()
    {
    Arr3[ctr3]=Arr1[ctr1];
    ctr1++;
    }
    public String copyArr2()
    {
    Arr3[ctr3]=Arr2[ctr2];
    ctr2++;
    }

  2. #2
    Takashy is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default Re: Merge sort

    Just a wild goes, but "public String copyArr1()" is probably in the wrong spot.. which is why it expects to see a class or interface and not a method. Also, it would make it a lot easier for us to find the problem if you would format the code a little bit.. and perhaps use the code tags.

    [edit] After taking a second look.. yup, it looks like your defining those methods outside of the class.
    Last edited by Takashy; 12-09-2011 at 09:19 AM.

  3. #3
    Aivy is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Merge sort

    so how can i include that in my class? please help me..

  4. #4
    Takashy is offline Member
    Join Date
    Feb 2011
    Posts
    9
    Rep Power
    0

    Default Re: Merge sort

    Not sure if you still need help (sorry for being so late), but basically your code looks like this..

    class..{
    //content
    }

    method1(){...}
    method2(){...}

    All you would have to do is move the last "{" of your class down so that it looks more like
    class{

    //content
    method1(){...}
    method2(){...}

    }

    Finding the right "{" shouldn't be too hard as long as you are using some decent editor. Basically you should be able to move your cursor in front or behind the first { of your class and it should automatically highlight the other one. (or give you some other visual clue to find the other } )

Similar Threads

  1. iterative merge sort
    By baf06 in forum New To Java
    Replies: 5
    Last Post: 10-23-2011, 09:17 PM
  2. merge sort with recursive method (need help badlly!!)
    By zetalore in forum Advanced Java
    Replies: 0
    Last Post: 01-08-2011, 07:10 PM
  3. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 01:03 AM
  4. Merge Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 07:43 PM
  5. Merge Sort Help
    By Hollywood in forum New To Java
    Replies: 5
    Last Post: 01-30-2008, 03:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •