Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. /*
  6. ===PSEUDOCODE===
  7. set swapMade to true
  8. while swapMade = 1
  9. set swapMade to 0
  10. Start at position 0 in the array
  11. for (position = 0; position != listlength-2; position++)
  12. if (position > position + 1)
  13. swap position with position + 1
  14. set swapMade to 1
  15. endIf
  16. endFor
  17. endWhile
  18. ===============
  19. */
  20.  
  21. int main(int argc, char **argv)
  22. {
  23. int swapMade, R0, R1, i, j;
  24. int array[] = {25, 10, 13, 9, 44, 15, 6, 2, 36, 42}; //10 long
  25.  
  26. swapMade = 1; //Set swapMade to true
  27. while(swapMade == 1)
  28. {
  29. swapMade = 0; //Set swapMade to false
  30. for(i = 0; i <= 8; i++)
  31. {
  32. R0 = array[i];
  33. R1 = array[i+1];
  34. if(R0 < R1) //Compare the two values
  35. {
  36. array[i] = R1; //Swap them
  37. array[i+1] = R0;
  38. swapMade = 1; //Set swapMade to 1
  39. }
  40. for(j = 0; j < 10; j++)
  41. {
  42. printf("%d, ", array[j]);
  43. }
  44. printf("\n");
  45. }
  46. printf("PASS COMPLETE\n");
  47. }
  48. printf("DATA SORTED\n");
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement