Advertisement
nontawat1996

sort struct

Mar 16th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct nn
  4. {
  5.     int num;
  6.     char id[10];
  7.     struct nn *next;
  8. }non;
  9. int cmp(const void *a,const void *b)
  10. {
  11.     non *aa=(non*)a;
  12.     non *bb=(non*)b;
  13.     if(aa->num>bb->num) return 1;
  14.     else return -1;
  15. }
  16. int main()
  17. {
  18.     non data[100];
  19.     int n;
  20.     int i;
  21.     scanf("%d",&n);
  22.     for(i=0;i<n;i++) scanf("%d",&data[i].num);
  23.     qsort(data,n,sizeof(non),cmp);
  24.     for(i=0;i<n;i++) printf("%d",data[i].num);
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement