Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   java bubble sort help (http://www.programmingforums.org/showthread.php?t=2573)

zip2kx Mar 4th, 2005 9:00 AM

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;
                        }
                }
        }
}
}
//

and this the part that calls the class in my app
:

//
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

Anything helpful is accepted :)

Dizzutch Mar 4th, 2005 9:14 AM

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.

zip2kx Mar 4th, 2005 9:26 AM

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 ).

Dizzutch Mar 4th, 2005 9:59 AM

ok, so DVDaAr data[] is what you wanna accept in sort()

zip2kx Mar 4th, 2005 11:13 AM

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 errors


Dizzutch Mar 4th, 2005 12:37 PM

what's hamtaLangd?

zip2kx Mar 4th, 2005 12:53 PM

a method that returns a private value

Dizzutch Mar 4th, 2005 1:47 PM

looks like you're not calling it according to it's signature

meribia_pro_software Mar 9th, 2005 9:00 PM

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/

Dizzutch Mar 9th, 2005 9:02 PM

his problem wasn't the algorithm, he had some syntax errors in his code.


All times are GMT -5. The time now is 4:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC