Answer to Question #30856 in C++ for asare patrick owusu

Question #30856
question: using c++ "Convert stack into two stacks. The first should contain only
positive numbers, and the second - negative.
1
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS