Advertisement
vim_fans

Untitled

Nov 23rd, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include <stdio.h>
  3.  
  4. #define MAX 10
  5.  
  6. int list[MAX] = {1, 8, 4, 6, 0, 3, 5, 2, 7, 9};
  7.  
  8. void display() {
  9.   int i;
  10.   printf("[");
  11.  
  12.   // navigate through all items
  13.   for (i = 0; i < MAX; i++) {
  14.     printf("%d ", list[i]);
  15.   }
  16.  
  17.   printf("]\n");
  18. }
  19.  
  20.  
  21.  
  22. void swap(int v[], int k)
  23. {
  24.     printf("swap v[k]=%d, for v[k+1]=%d",v[k],v[k+1]);
  25.     int temp;
  26.     temp = v[k];
  27.     v[k] = v[k+1];
  28.     v[k+1] = temp;
  29. }
  30.  
  31. void sort (int v[], int n)
  32. {
  33.     int i,j;
  34.     for(i=0; i<n;i+=1){
  35.         printf("i equals to %d",i);
  36.         for(j = i-1;j>=0 && v[j]>v[j+1];j=1){
  37.             swap(v,j);
  38.         }
  39.     }
  40. }
  41. int main() {
  42.     printf("Input Array: ");
  43.     display();
  44.     sort(list,MAX);
  45.     printf("\n");
  46.  
  47.     printf("\nOutput Array: ");
  48.     display();
  49.  
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement