My bubble sort only sorts once
Hi, i have been endlessly trying to make this bubble sort work. what happens is that i have to manually keep pressing 3 (this is my option to sort the data) for each swap, whereas i want the whole array sorted in one go. The function i have written is part of a CNC menu program where the user enters a number to perform a specific task. My bubble sort is shown below. The problem im having is that it is only swapping 2 numbers, then i press 3 and it sorts again etc. My question is how do i loop the whole thing to sort everything in one go?
Many thanks
EDIT: x is the number of values the user requests to be sorted
Code:
void bubblesortascending(float myarray[999][3],int x)
{
int i,countfrom;
float tempx,tempy,tempdrillsize;
countfrom=0;
for(i=1;i<=x-1;i++)
{
countfrom++;
if(myarray[i][0]>myarray[i+1][0])
{
tempx=myarray[i][0];
tempy=myarray[i][1];
tempdrillsize=myarray[i][2];
myarray[i][0]=myarray[i+1][0];
myarray[i][1]=myarray[i+1][1];
myarray[i][2]=myarray[i+1][2];
myarray[i+1][0]=tempx;
myarray[i+1][1]=tempy;
myarray[i+1][2]=tempdrillsize;
}
}
printf("To view the sorted data, please press 4 to display the array\n\r");
return;
}