The application of the stack in the transformation of the system

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.