Advertisements

Data Structure in Java, please help

Postby baranbilgi » Wed Oct 10, 2012 5:04 am

Offline
baranbilgi
Posts: 1
Joined: Wed Oct 10, 2012 5:00 am
Location: scottsdale
I am trying to add comparison and swap, I am freak out, what am I supposed to do? I really dont have any idea, please someone help, I need missing part.

[/code]public class BubbleSort{
public static void main(String a[]){
int i;

int array[] = {21,33,7,25};

bubblesort(array, array.length);
for(i = 0; i <array.length; i++){
System.out.print(array[i]+" ");

}}

public static void bubblesort( int a[], int N ){
int i, j, t=0;
for(i = 0; i < N; i++){
for(j = 1; j < (N-i); j++){
if(a[j-1] > a[j]){
SWAP(a[j-1],a[j]);
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}}

private static void SWAP(int i, int j) {
// TODO Auto-generated method stub

}}[code][/code]