Guest User

Sort Structure

a guest
Apr 12th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef struct test
  4. {
  5.     int first_val;
  6.     int second_val;
  7. }test;
  8. bool func(test a,test b)
  9. {
  10.     if(a.second_val<b.second_val)
  11.     return 1;
  12.     else return 0;
  13. }
  14. int main()
  15. {
  16.     test arr[] = { {5,6} , {8,1} , {6,4} , {4,9} , {2,9} , {7,3} };
  17.     int n=sizeof(arr)/sizeof(test);
  18.     sort(arr,arr+n,func);
  19.     for(int i=0;i<n;i++)
  20.     {
  21.         cout<<arr[i].first_val<<" "<<arr[i].second_val<<endl;
  22.     }
  23. }
Add Comment
Please, Sign In to add comment