1 Star 0 Fork 0

付峻霖/数据结构

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
十进制数转八进制数 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
付峻霖 提交于 2021-04-11 19:54 . add 十进制数转八进制数.
#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef struct SNode
{
int data;
struct SNode* next;
}SNode, * LinkStack;
Status InitStack(LinkStack& S)
{
S = NULL;
return OK;
}
bool StackEmpty(LinkStack S)
{
if (!S)
return true;
return false;
}
Status Push(LinkStack& S, int e)//进栈
{
LinkStack p;
p = new SNode;
if (!p)
{
return OVERFLOW;
}
p->data = e;
p->next = S;
S = p;
return OK;
}
Status Pop(LinkStack& S, int& e)
{
LinkStack p;
if (!S)
{
return ERROR;
}
e = S->data;//保存出栈数据
p = S;
S = S->next;//往下走一格
delete p;
return OK;
}
void conversion(int N)
{
int e;
LinkStack S;
InitStack(S);
while (N)
{
Push(S, N % 8);
N = N / 8;
}
while (!StackEmpty(S))
{
Pop(S, e);
cout <<e;
}
}
int main()
{
int n, e;
cout << "请输入您要转化的十进制数:";
cin>>n;
cout << "对应的八进制数为:";
conversion(n);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/fujunlin/data-structure.git
git@gitee.com:fujunlin/data-structure.git
fujunlin
data-structure
数据结构
master

搜索帮助