栈的应用之进制转化
2015-05-09 16:10
190 查看
顺序栈的代码:
不再赘述:点击打开链接
不再赘述:点击打开链接
//栈的应用-----进制转化 #include"stack.h" int main() { Stack st; InitStack(&st); int select; int num1; //要转化的数 int num2; //转化之后各个位的数 int flag = 1; //控制循环结束 while(flag) { cout<<"****************进制转换*****************"<<endl; cout<<"*[1]十转二 [2]十转八*"<<endl; cout<<"*[3]十转十六 [4]退出 *"<<endl; cout<<"please choose the function num you:"<<endl; cin>>select; switch(select) { case 1: //2进制转化 cout<<"input the num you 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进制转化 cout<<"input the num you 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进制转化 cout<<"input the num you 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中的数 { cout<<(char)(num2 - 10 + 'A'); //强制类型转化 } else cout<<num2;//0----9中的数 } cout<<endl; break; case 4: select = 0; break; default: break; } } destory(&st); return 0; }
相关文章推荐
- shell脚本编程应用:进制转化,bc中的ibase与obase
- python数据结构 栈的应用——符号匹配,进制转化,后缀。
- javascript中的栈以及其应用十进制转化为其他进制
- 栈的应用-进制转化
- 进制转化(栈应用)
- 好的JAVA思路——利用补码运算和位运算的巧用来实现进制转化
- 第十二周OJ——十进制转化任意进制
- 各进制转化
- UVa 11121 - Base -2 负进制的转化和推广
- 十进制数任意转换2-9进制数——栈的应用
- C++10进制字符串与十六进制字符串相互转化
- IT 人员必学的最基础知识(二)——进制相互转化
- FZU 2102 Solve equation(水,进制转化)&& FZU 2111(贪心,交换使数字最小)
- N进制数字及“移码”应用
- codeforce 13 A && hdu 2031 有关进制的转化
- hdu 1042 N!(大数阶乘,转化为100000这样的比较大的进制)
- 进制转化之递归 && 栈
- 中缀表达式转化为后缀表达式(栈的应用)
- 中缀表达式转化为后缀表达式(栈的应用)
- 2 进制的转化