Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. void bubbleSort(int list[], int size)
  2. {
  3. int help;
  4.  
  5. for(int i=0;i<size;i++)
  6. {
  7. for(int j=0;j<size;j++)
  8. {
  9. if(list[j+1] < list[j])
  10. {
  11. help = list[j+1];
  12. list[j+1] = list[j];
  13. list[j]=help;
  14. }
  15. }
  16. }
  17. }
  18.  
  19. void insertionSort(int list[], int size){
  20. int help;
  21. for(int i=0;i<size;i++)
  22. {
  23. int j = i + 1;
  24. help = list[j];
  25. while(j > 0 && help < list[j-1])
  26. {
  27. list[j] = list[j-1];
  28. j--;
  29. }
  30. list[j] = help;
  31. }
  32. }
  33.  
  34. void selectionSort(int list[], int size)
  35. {
  36. int help;
  37. for(int i = 0; i < size; i++)
  38. {
  39. int maxIndex = i;
  40. for(int j=i+1; j < size; j++)
  41. {
  42. if(list[j] < list[maxIndex])
  43. {
  44. maxIndex =j;
  45. }
  46. }
  47. help = list[i];
  48. list[i] = list[maxIndex];
  49. list[maxIndex] = help;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement