![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
java bubble sort help
Right i cant get it to work and im out of ideas so some programmring guru plz help T__T
this is my bubblesort class file: public class sort{
public static void bubbelSort(film data[]){
for (int m = data.lenght -1; m > 0; m--){
for (int n = 0; n < m; n++){
if(data[n].langd > data[n+1].langd){
int temp = data[n].langd;
data[n].langd = data[n+1].langd;
data[n+1].langd = temp;
}
}
}
}
}
////
sort.bubbelSort(film);
System.out.print("Sorterad efter langd: ");
for (int i = 0; i < 5; i++){
System.out.print(film[i] + " ");
}note that it's in a case. and the error i get when i javac it //
D:\Java grejer>javac inlupp_DVDDaAr.java
.\sort.java:3: cannot resolve symbol
symbol : class film
location: class sort
public static void bubbelSort(film data[]){
^
1 error![]() |
|
|
|
|
|
#2 |
|
Professional Programmer
|
what's film? is there a class called film? you're passing film into the sort method, but that's the name of the variable, when you create film, you must do something like [Class] film = new [Class]() the name of the Class is the Type of variable you're passing through.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
oh crap forgot that. Film is a "array" (i think... im translating from swedish -> english so it might be wrong)
i used it to DVDDaAr film[]=new DVDDaAr[100]; DVDDAaAr is the main class file that sorts the other information that i send in (it works ). |
|
|
|
|
|
#4 |
|
Professional Programmer
|
ok, so DVDaAr data[] is what you wanna accept in sort()
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
So it's
sort.bubbelSort(DVDDaAr data[]); ? or did i get it wrong? edit: changed some stuff. i Changed Public static void bubbelSort(film data[]){
to
Public static void bubbelSort(DVDDaAr data[]){and for (int m = data.lenght -1; m > 0; m--){
to
for (int m = data.length -1; m >0; m--){every .langd to .hamtaLangd .hamtaLangd is a getter which returns a int. and now im stuck with these 2 last errors .\sort.java:8: unexpected type
required: variable
found : value
data[n].hamtaLangd() = data[n+1].hamtaLangd();
^
.\sort.java:9: unexpected type
required: variable
found : value
data[n+1].hamtaLangd() = temp;
^
2 errorsLast edited by zip2kx; Mar 4th, 2005 at 12:04 PM. |
|
|
|
|
|
#6 |
|
Professional Programmer
|
what's hamtaLangd?
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
a method that returns a private value
|
|
|
|
|
|
#8 |
|
Professional Programmer
|
looks like you're not calling it according to it's signature
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
Hello all, I'm new to this forum, but I consider myself an expert in Java (as well as in 6 other computer languages). I think I can help out with this problem if anyone's still paying attention to this thread ....
I wrote a small C++ routine that implements the Bubble Sort algorithm a while back and it should be able to be ported to Java quite easily. Here it is: void SortObject::bubbleSort () { int i; int tmp; for ( i = 0; i < count - 1; i++ ) { if ( array[i] > array[i+1] ) { tmp = array[i]; array[i] = array[i+1]; array[i+1] = tmp; i = 0; } } } -------------------------------------------------------------------------------- Download SortObject++: veritedonato.cihost.com/sort.zip MainWebsite: veritassoftwarecreations.net/ |
|
|
|
|
|
#10 |
|
Professional Programmer
|
his problem wasn't the algorithm, he had some syntax errors in his code.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|