Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <ctime>
- #include <cstdlib>
- #include<algorithm>
- using namespace std;
- int ran(int a1, int a2)
- {
- return rand()*rand()%(a2-a1+1)+a1;
- }
- typedef struct ranList
- {
- int a,b,c;
- }ranList;
- void Print(ranList *arr)
- {
- cout << "\nArray A: ";
- for (int i=0;i<100;i++)
- {
- cout << arr[i].a << " ";
- }
- cout << "\nArray B: ";
- for (int i=0;i<100;i++)
- {
- cout << arr[i].b << " ";
- }
- cout << "\nArray C: ";
- for (int i=0;i<100;i++)
- {
- cout << arr[i].c << " ";
- }
- }
- bool compareFunc(ranList r1, ranList r2)
- {
- return r1.b < r2.b;
- }
- int main()
- {
- freopen("Result.txt","w",stdout);
- srand((unsigned)(time(NULL)));
- ranList arr[100];
- for (int i=0;i<100;i++)
- {
- arr[i].a = ran(0,2000);
- arr[i].b = ran(0,2000);
- arr[i].c = ran(0,2000);
- }
- cout << "\nBefore: \n";
- Print(arr);
- sort(arr,arr+100,compareFunc);
- cout << "\nAfter: \n";
- Print(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment