Results 1 to 4 of 4
Thread: Merge sort
- 12-09-2011, 06:05 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
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++;
}
- 12-09-2011, 09:17 AM #2
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
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.
- 12-09-2011, 09:43 AM #3
Member
- Join Date
- Nov 2011
- Posts
- 3
- Rep Power
- 0
Re: Merge sort
so how can i include that in my class? please help me..
- 12-14-2011, 11:29 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 9
- Rep Power
- 0
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
-
iterative merge sort
By baf06 in forum New To JavaReplies: 5Last Post: 10-23-2011, 09:17 PM -
merge sort with recursive method (need help badlly!!)
By zetalore in forum Advanced JavaReplies: 0Last Post: 01-08-2011, 07:10 PM -
Using Merge Sort to sort an ArrayList of Strings
By coldfire in forum New To JavaReplies: 3Last Post: 03-13-2009, 01:03 AM -
Merge Sort in Java
By Java Tip in forum AlgorithmsReplies: 0Last Post: 04-15-2008, 07:43 PM -
Merge Sort Help
By Hollywood in forum New To JavaReplies: 5Last Post: 01-30-2008, 03:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks