fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. struct Worker
  7. {
  8. char pib[40];
  9. char posada[40];
  10. int year;
  11. };
  12.  
  13. void InsertionSort(Worker *array, int n)
  14. {
  15. Worker tmp;
  16. for (int i = 1,j; i < n; i++)
  17. {
  18. tmp = array[i];
  19. for ( j=i-1; j>=0 && strcmp(array[j].pib, tmp.pib) > 0;j--)
  20. array[j + 1] = array[j];
  21. array[j + 1] = tmp;
  22. }
  23. }
  24.  
  25. int main() {
  26. Worker arr[] = {{"ABC","DEF",1},{"XYZ","NFM",2},{"OPQ","FNF",3}};
  27. for(auto &worker: arr)
  28. cout<<worker.pib<<" -- "<<worker.posada<<" -- "<<worker.year<<endl;
  29. InsertionSort(arr, 3);
  30. cout<<"-----------------------------"<<endl;
  31. for(auto &worker: arr)
  32. cout<<worker.pib<<" -- "<<worker.posada<<" -- "<<worker.year<<endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
ABC -- DEF -- 1
XYZ -- NFM -- 2
OPQ -- FNF -- 3
-----------------------------
ABC -- DEF -- 1
OPQ -- FNF -- 3
XYZ -- NFM -- 2