HW2 - while (S1.empty()==False){ element=S1.top(); S1.pop()...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
///A. #include <iostream> # using namespace std; int main(){ double x; int times=0; int n=3; cin >> x; while (n > 1){ x=x/2; times++; if (x<2){ n=0;} } cout << times; } ///E. #include <stack> # template <typename Object> class queue { private: p // Do not use any data members other than the following two stacks std::stack<Object> S1; std::stack<Object> S2; public: p bool empty() const { return (S1.empty() & S2.empty()); } int size() const { return (S1.size()+ S2.size()); } S1.push(item); } void pop() { if (S2.empty()){
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: while (S1.empty()==False){ element=S1.top(); S1.pop() S2.push(element) } } } Object&amp; front() { return S2.top(); } // for simplicity, we'll ignore the const version of front() } //Extra Credit f() would return whatever integer inputted plus 1. f(int 2) would return 3. g() would return whatever the integer's memory address plus 1. g(int&amp; 3) {address is 1200) would return 1201. h() would return whatever the integer's memory address. h(const int&amp; 3) would return 1200....
View Full Document

Page1 / 2

HW2 - while (S1.empty()==False){ element=S1.top(); S1.pop()...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online