SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<stack>
  3. #include<exception>
  4. std::ostream &operator<<(std::ostream &tok,std::stack<int> s)
  5. {
  6.     while(!s.empty())
  7.     {
  8.         tok<<s.top()<<" ";
  9.         s.pop();
  10.     }
  11.     return tok;
  12. }
  13. std::stack<int> operator-(std::stack<int> s1, std::stack<int> s2)
  14. {
  15.     if(s1.size()!=s2.size()) throw std::logic_error("NeS MOC");
  16.     std::stack<int>s3;
  17.     int razlika;
  18.     while(!s1.empty())
  19.     {
  20.         razlika=s1.top()-s2.top();
  21.         s3.push(razlika);
  22.         s1.pop();s2.pop();
  23.     }
  24.     return s3;
  25. }
  26. void operator*=(std::stack<int>&s1,int n)
  27. {
  28.     std::stack<int>pom;
  29.     int broj;
  30.     while(!s1.empty())
  31.     {
  32.         broj=s1.top()*n;
  33.         pom.push(broj);
  34.         s1.pop();
  35.     }
  36.     while(!pom.empty())
  37.     {
  38.         s1.push(pom.top());
  39.         pom.pop();
  40.     }
  41. }
  42. bool operator*(const std::stack<int> &s)
  43. {
  44.     bool prazan=1;
  45.     if(s.empty()) prazan=0;
  46.     return prazan;
  47. }
  48. int main()
  49. {
  50.     int niz1[] {1, 5, 7, 3}, niz2[] {1, 9, 0, 4};
  51.     std::stack<int> q1, q2;
  52.     for(auto i : niz1) q1.push(i); // ubacimo elemente
  53.     for(auto i : niz2) q2.push(i); // redoslijed je OBRNUT
  54.     std::cout << q2 << std::endl; // 4 0 9 1 - ispis
  55.     // moraju biti istih dimenzija, inace baciti izuzetak po volji!
  56.     std::cout << q1 - q2<<std::endl; // 0, -4, 7, -1 ispis
  57.     q1 *= 3; // q1 = {9, 21, 15, 3} - redoslijed OBRNUT
  58.     std::cout << q1 << std::endl;
  59.     if(*q1) std::cout << "Nije prazan";
  60.     else std::cout << "Prazan";
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top