daily pastebin goal
27%
SHARE
TWEET

nap sort

a guest Dec 18th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void sort(int a[], int n, int *p)
  4. {
  5.     int max, x;
  6.     for(int i=0; i<n; i++)
  7.     {
  8.         max=a[0];
  9.         x=0;
  10.         for(int j=1; j<n; j++)
  11.         {
  12.             if(a[j]>max)
  13.             {
  14.                 max=a[j];
  15.                 x=j;
  16.             }
  17.         }
  18.         *p=max;
  19.         p++;
  20.         a[x]=0;
  21.     }
  22. }
  23.    
  24.  
  25. int main()
  26. {
  27.     int n;
  28.     scanf("%d",&n);
  29.     int a[n], b[n];
  30.     for(int i=0; i<n; i++)
  31.         scanf("%d",&a[i]);
  32.        
  33.     sort(a, n, &b[0]);
  34.    
  35.     for(int i=0; i<n; i++)
  36.         printf("%d ", b[i]);
  37.    
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand