Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bubble sort

Status
Not open for further replies.

Eytch

Programmer
Jan 29, 2003
60
US
Hi,

I'm trying to do a bubble sort on an employee Id field. After the sort the employee Id's along with the corresponding salaries will be sorted in descending order by Id.
Upon compiling, I get one error message as follows:

E:\EmployeeSort.java:26: bubbleSort(Employee[],int) in EmployeeSort cannot be applied to (int[],int)
bubbleSort(empNum,empNum.length);

Generated from the program that follows:

import javax.swing.*;
public class EmployeeSort
{
public static void main(String[] args)
{
//declare array of 5 employees
Employee[] someEmployee = new Employee [5];


int [] empNum = {3,2,1,5,4};

double [] empSal = {20.15, 15.60, 11.24, 8.34, 25.12};

int i;

for(i=0; i < 5; i++)
e = empNum ;
s = empSal ;
someEmployee = new Employee(e,s);


System.out.println
("Before the sort Employee number " + empNum + " has a salary of " + empSal);

bubbleSort(empNum,empNum.length);
for(i=0; i < empNum.length; i++)
System.out.println
("After the sort Employee number " + empNum + " has a salary of " + empSal);

}
public static void bubbleSort(Employee [] array, int len)
{
int a,b;
Employee temp;
int highSubscript = len -1;
for(a=0; a<highSubscript; ++a)
for(b = 0; b <highSubscript; ++b)
if(array.getEmpNum() < array[b+1].getEmpNum())
{
temp = array;
array = array[b+1];
array[b+1] = temp;
}

}//end of main
}//end of class

Any suggestions on where my problem is?

Thanks,
Tripoli



^
 
I didn't do a deep read of your code, but at first sigth, your buble Orden method is expecting an employee array and you're a passing just the Id array.

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top