Advertisement
sellmmaahh

popravni-2014-zad7-Sortiranje Kompleksnih

Jul 31st, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <deque>
  4. #include <complex>
  5.  
  6. using namespace std;
  7.  
  8. bool Kriterij (complex<double> z1, complex<double> z2)
  9. {
  10.     if (abs(z1)==abs(z2)) return z1.real()<z2.real();
  11.     else return abs(z1)<abs(z2);
  12. }
  13. int main () {
  14.     int n;
  15.     cout<<"Unesite n :";
  16.     cin>>n;
  17. deque<complex<double>> d(0);
  18. cout<<"Unesite elemente deka u obliku (x,y): ";
  19. complex<double> z;
  20. for (int i=0; i<n; i++) {
  21.     cin>>z;
  22.     d.push_back(z);
  23. }
  24. sort(d.begin(), d.end(), Kriterij);
  25. for (auto x : d) cout<<x<<" ";
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement