Answer to Question #30856 in C++ for asare patrick owusu
2013-05-20T04:45:02-04:00
question: using c++ "Convert stack into two stacks. The first should contain only
positive numbers, and the second - negative.
1
2013-05-21T10:18:45-0400
#include <iostream> #include <string> #include<iostream> #include<stack> using namespace std; int main() { stack<int> A; stack<int> B; stack<int> C; int temp; for(int i=0;i<10;i++) { A.push(-5+i); } while(! A.empty()){ temp = A.top(); A.pop(); if (temp < 0) B.push(temp); else C.push(temp); } cout<<"\nnegative stack\n"; int l=B.size(); for(int i=0;i<l;++i) { cout<<B.top()<<" "; B.pop(); } cout<<"\npositivee stack\n"; l=C.size(); for(int i=0;i<l;++i) { cout<<C.top()<<" "; C.pop(); } system ("PAUSE"); return 0; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments
Leave a comment