Code for the sequential stack:
Don't repeat: Click to open link
The application of the stack-----conversion include "stack.h" int main () {stack st;initstack (&st); int select;int num1; The number of int num2 to convert; The number of individual bits after conversion int flag = 1; Control Loop End while (flag) {cout<< "**************** conversion *****************" <<endl;cout<< "*[1] 10 turn Two [2] 10 ext. Eight * "<<endl;cout<<" *[3] 10 ext. 16 [4] Exit * "<<endl;cout<<" Please choose the funct Ion num: "<<endl;cin>>select;switch (SELECT) {Case 1://2 conversion cout<<" input the num want to Transform: "<<endl;cin>>num1;while (NUM1) {Push (&st,num1%2); Num1/= 2;} cout<< "The result is:" <<endl;while (! IsEmpty (&st)) {Pop (&st,&num2); cout<<num2;} Cout<<endl;break;case 2://8 conversion cout<< "input the num want to transform:" <<endl;cin>>num1; while (NUM1) {Push (&st,num1%8); Num1/= 8;} cout<< "The result is:" <<endl;while (! IsEmpty (&st)) {Pop (&st,&num2); cout<<num2;} Cout<<endl;break;case 3://16 conversion cout<< "input the num want to transform:" <<endl;cin>>num1;while (NUM1) {Push (&st,num1%16); NUM1/= 16;} cout<< "The result is:" <<endl;while (! IsEmpty (&st)) {Pop (&st,&num2), if (num2 > 9)//a---f number {cout<< (char) (num2-10 + ' A ');//Forced type conversion} elsecout<<num2;//0----9 of the number}cout<<endl;break;case 4:select = 0;break;default:break;}} Destory (&st); return 0;}
The application of the stack in the transformation of the system