Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*
- ===PSEUDOCODE===
- set swapMade to true
- while swapMade = 1
- set swapMade to 0
- Start at position 0 in the array
- for (position = 0; position != listlength-2; position++)
- if (position > position + 1)
- swap position with position + 1
- set swapMade to 1
- endIf
- endFor
- endWhile
- ===============
- */
- int main(int argc, char **argv)
- {
- int swapMade, R0, R1, i, j;
- int array[] = {25, 10, 13, 9, 44, 15, 6, 2, 36, 42}; //10 long
- swapMade = 1; //Set swapMade to true
- while(swapMade == 1)
- {
- swapMade = 0; //Set swapMade to false
- for(i = 0; i <= 8; i++)
- {
- R0 = array[i];
- R1 = array[i+1];
- if(R0 < R1) //Compare the two values
- {
- array[i] = R1; //Swap them
- array[i+1] = R0;
- swapMade = 1; //Set swapMade to 1
- }
- for(j = 0; j < 10; j++)
- {
- printf("%d, ", array[j]);
- }
- printf("\n");
- }
- printf("PASS COMPLETE\n");
- }
- printf("DATA SORTED\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement