Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. void BubbleSort(float vector[], int numValues);
  2. You should do this by translating the following pseudocode into c.
  3. Outside of main,
  4. Define LISTSIZE as a #defined constant value 10
  5. void BubbleSort(float vector[], int numValues);
  6. Inside of main
  7. Declare list, an array of real (floats), sized LISTSIZE
  8. Declare temp, as a real variable
  9. Declare i, and count as integer variables
  10. Prompt the user to input up to LISTSIZE positive real values, where -1 terminates the input when less than LISTSIZE values are being input.
  11. Using a for loop, set i=0; test i < LISTSIZE; i=i+1
  12. Input a real value into the temp variable
  13. If temp is equal to -1, break out of the for loop
  14. Set list[i] = temp
  15. END of for loop
  16. Set count = i; //count is the number of values in list
  17. Use a for loop to print out list[0] -> list[count-1]
  18. ////// Now sort the list with a bubble sort
  19. BubbleSort(list,count);
  20. /////// Now the list is sorted
  21. Use a for loop to print out list[0] -> list[count-1]
  22. End of main
  23.  
  24. void BubbleSort(float vector[], int numValues)
  25. Inside of BubbleSort
  26. Declare i, count, and swapCount as integer variables
  27. Declare temp as a real variable
  28.  
  29. DO
  30. swapCount = 0
  31. for i=0; i<(count-1); i=i+1
  32. IF vector[i] > vector[i+1] then
  33. temp = vector[i]
  34. vector[i] = vector[i+1]
  35. vector[i+1] = temp
  36. swapCount = swapCount + 1
  37. END of IF
  38. END of for loop
  39. WHILE swapCount > 0;
  40. End of Bubble Sort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement