Advertisement
naskedvi

S5 - zad.25

Apr 26th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <complex>
  4. typedef std::complex<double> Kompleksni;
  5.  
  6. bool Manji(Kompleksni x, Kompleksni y)
  7. {
  8.     if((std::imag(x)<std::imag(y)) ||
  9.        (std::imag(x)==std::imag(y) && std::real(x)<std::real(y)))
  10.             return true;
  11.     else return false;
  12. }
  13.  
  14. int main()
  15. {
  16.     std::cout<<"Unesi broj elemenata: ";
  17.     int n;
  18.     std::cin>>n;
  19.     Kompleksni niz[n];
  20.     std::cout<<std::endl<<"Unesi kompleksne brojeve:"<<std::endl;
  21.     for(int i=0; i<n; i++)
  22.     {
  23.         Kompleksni a;
  24.         std::cin>>a;
  25.         niz[i]=a;
  26.     }
  27.  
  28.     std::sort(niz, niz+n, Manji);
  29.  
  30.     for(int i=0; i<n; i++)
  31.       std::cout<<niz[i]<<" ";
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement