Hey im wondering what is wrong with this bubble sort code:
Code:
while (swapped){
swapped=0;
for(i=0; i<unsrtlen-1;i=i+1) {
if (array[i+1][4]<array[i][4]) {
for(j=0;j<5;j++) {
help=array[i][j];
array[i][j]=array[i+1][j];
array[i+1][j]=help;
swapped=1;
}
j=0;
}
}
unsrtlen=unsrtlen-1;
}
this is just a part of my program....
I have a 2d array of elements [10][5] and i want to sort the last element on the right hand side in ascending order which means that i have to move a whole line of elements up...
It compiles fine but when i print it in a table i get a bunch of random numbers..
Why is this so????
Any help will be appreciated...