{ for(j=i+1;j { if(data[i]>data[j]) { temp=data[i]; data[i]=data[j]; data[j]=temp; } //if loop } //for j loop }//for i loop You can optimize the algorithm by exiting the loop if there is no swapping in a particular loop. Hope this helps Regards, PraveenG