您的位置:首页 > 其它

栈实现10进制到8进制的转换

2015-01-21 15:53 549 查看
数据结构 严蔚敏 P48

#include<iostream>
#include<string>
#include<stack>
using namespace std;
string conversion(int num){
stack<int> intstack;
int temp;
string str,strtemp;
while (num){
intstack.push(num % 8);
num = num / 8;
}
while (!intstack.empty()){
temp = intstack.top();
intstack.pop();
strtemp = to_string(temp);
str += strtemp;
}
return str;
}
int main()
{
string s;
s = conversion(1348);
cout << s << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: