Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- #include<exception>
- std::ostream &operator<<(std::ostream &tok,std::stack<int> s)
- {
- while(!s.empty())
- {
- tok<<s.top()<<" ";
- s.pop();
- }
- return tok;
- }
- std::stack<int> operator-(std::stack<int> s1, std::stack<int> s2)
- {
- if(s1.size()!=s2.size()) throw std::logic_error("NeS MOC");
- std::stack<int>s3;
- int razlika;
- while(!s1.empty())
- {
- razlika=s1.top()-s2.top();
- s3.push(razlika);
- s1.pop();s2.pop();
- }
- return s3;
- }
- void operator*=(std::stack<int>&s1,int n)
- {
- std::stack<int>pom;
- int broj;
- while(!s1.empty())
- {
- broj=s1.top()*n;
- pom.push(broj);
- s1.pop();
- }
- while(!pom.empty())
- {
- s1.push(pom.top());
- pom.pop();
- }
- }
- bool operator*(const std::stack<int> &s)
- {
- bool prazan=1;
- if(s.empty()) prazan=0;
- return prazan;
- }
- int main()
- {
- int niz1[] {1, 5, 7, 3}, niz2[] {1, 9, 0, 4};
- std::stack<int> q1, q2;
- for(auto i : niz1) q1.push(i); // ubacimo elemente
- for(auto i : niz2) q2.push(i); // redoslijed je OBRNUT
- std::cout << q2 << std::endl; // 4 0 9 1 - ispis
- // moraju biti istih dimenzija, inace baciti izuzetak po volji!
- std::cout << q1 - q2<<std::endl; // 0, -4, 7, -1 ispis
- q1 *= 3; // q1 = {9, 21, 15, 3} - redoslijed OBRNUT
- std::cout << q1 << std::endl;
- if(*q1) std::cout << "Nije prazan";
- else std::cout << "Prazan";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement