matheus__serpa

sort_struct

Aug 27th, 2020
1,451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. void swap(funcionario *A, funcionario *B){
  2.     funcionario tmp = *A;
  3.     *A = *B;
  4.     *B = tmp;
  5. }
  6.  
  7. void selection_sort(funcionario *A, int N){
  8.     int i, j, min;
  9.     for(i = 0; i < N - 1; i++){
  10.         min = i;
  11.         for(j = i + 1; j < N; j++)
  12.             if(A[j].salario < A[min].salario)
  13.                 min = j;
  14.         if(A[i].salario != A[min].salario)
  15.             swap(&A[i], &A[min]);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment