Lyra

Untitled

Nov 20th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. /* SWAP : algo d'échange */
  2. void swap(int iArray[], int index1, int index2)
  3. {
  4. int temp;
  5. temp = iArray[index1];
  6. iArray[index1] = iArray[index2];
  7. iArray[index2] = temp;
  8. }
  9.  
  10. /* BUBBLE : classe tableau ordre croissant */
  11. void bubbleSort(int size, int iArray[])
  12. {
  13. int cmpt;
  14. int isSorted = 0;
  15. do
  16. {
  17. isSorted = 1;
  18. for(cmpt=0; cmpt<size-1; cmpt++)
  19. {
  20. int cmptBis = cmpt+1;
  21. if (iArray[cmpt] > iArray[cmptBis])
  22. {
  23. swap (iArray, cmpt, cmptBis);
  24. isSorted = 0;
  25. }
  26. }
  27. } while (isSorted == 0);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment