dimanche 25 janvier 2015

Stack program in c issue


Hello can anyone help me with my code? This stack program is supposed to give you the result of an input of characters (words and ? #) when it reads ? It deletes the word that goes before it, and when it reads # it deletes the whole list of previous characters, for example: fgsjdjabc?d#fg? So the result should be f But the problem is that my program shows you the result inverted, can anyone help me how to change it so it shows me the regular way?



#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <stack>

using namespace std;
int main (int argc, char *argv[])
{
int e=0,i,a;
stack<char> s;
while (e==0){
scanf("%c",&i);
if (i!= '#' && i!= '?' &&i!= 'X'){
s.push(i);
}
else if (i== '#'){

s.top() ;
s.pop();
}
else if (i== '?' ){
while (! s.empty()) {
s.top();
s.pop();
}
}
else if (i== 'X' ){
e=e+1;
}
}
printf("\n");
while (! s.empty() ) {
cout << s.top() << "" ;
s.pop();
}
cout << end1;
system("PAUSE");
return EXIT_SUCCESS;
}




Aucun commentaire:

Enregistrer un commentaire