Guest User

Untitled

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. typedef struct elemento {
  2. unsigned long linha;
  3. unsigned long coluna;
  4. double valor;
  5. } elemento;
  6.  
  7. elemento Representados[MAXN];
  8. qsort(Representados, index, sizeof(Representados[0]), lcomparator);
  9.  
  10. int lcomparator(const void *el1, const void *el2) {
  11. int l1 = ((elemento *)el1)->linha;
  12. int l2 = ((elemento *)el2)->linha;
  13. int c1 = ((elemento *)el1)->coluna;
  14. int c2 = ((elemento *)el2)->coluna;
  15.  
  16. if (l1 < l2) {
  17. return -1;
  18. }
  19. else if (l1 == l2) {
  20. if (c1 < c2) {
  21. return -1;
  22. }
  23. else if (c1 == c2) {
  24. return 0;
  25. }
  26. else if (c2 > c1) {
  27. return 1;
  28. }
  29. }
  30. else {
  31. return 1;
  32. }
  33.  
  34. }
Add Comment
Please, Sign In to add comment