60 642
Assignments Done
97,8%
Successfully Done
In April 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions