Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdio.h>
- #define MAX 10
- int list[MAX] = {1, 8, 4, 6, 0, 3, 5, 2, 7, 9};
- void display() {
- int i;
- printf("[");
- // navigate through all items
- for (i = 0; i < MAX; i++) {
- printf("%d ", list[i]);
- }
- printf("]\n");
- }
- void swap(int v[], int k)
- {
- printf("swap v[k]=%d, for v[k+1]=%d",v[k],v[k+1]);
- int temp;
- temp = v[k];
- v[k] = v[k+1];
- v[k+1] = temp;
- }
- void sort (int v[], int n)
- {
- int i,j;
- for(i=0; i<n;i+=1){
- printf("i equals to %d",i);
- for(j = i-1;j>=0 && v[j]>v[j+1];j=1){
- swap(v,j);
- }
- }
- }
- int main() {
- printf("Input Array: ");
- display();
- sort(list,MAX);
- printf("\n");
- printf("\nOutput Array: ");
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement