Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BubbleSort(float vector[], int numValues);
- You should do this by translating the following pseudocode into c.
- Outside of main,
- Define LISTSIZE as a #defined constant value 10
- void BubbleSort(float vector[], int numValues);
- Inside of main
- Declare list, an array of real (floats), sized LISTSIZE
- Declare temp, as a real variable
- Declare i, and count as integer variables
- Prompt the user to input up to LISTSIZE positive real values, where -1 terminates the input when less than LISTSIZE values are being input.
- Using a for loop, set i=0; test i < LISTSIZE; i=i+1
- Input a real value into the temp variable
- If temp is equal to -1, break out of the for loop
- Set list[i] = temp
- END of for loop
- Set count = i; //count is the number of values in list
- Use a for loop to print out list[0] -> list[count-1]
- ////// Now sort the list with a bubble sort
- BubbleSort(list,count);
- /////// Now the list is sorted
- Use a for loop to print out list[0] -> list[count-1]
- End of main
- void BubbleSort(float vector[], int numValues)
- Inside of BubbleSort
- Declare i, count, and swapCount as integer variables
- Declare temp as a real variable
- DO
- swapCount = 0
- for i=0; i<(count-1); i=i+1
- IF vector[i] > vector[i+1] then
- temp = vector[i]
- vector[i] = vector[i+1]
- vector[i+1] = temp
- swapCount = swapCount + 1
- END of IF
- END of for loop
- WHILE swapCount > 0;
- End of Bubble Sort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement