当前位置:网站首页>DS(StackAnQueueBasiApplication)
DS(StackAnQueueBasiApplication)
2022-07-19 12:54:00 【itfunc】
#include <bits/stdc++.h>
using namespace std;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef struct {
int *base;
int *top;
int stacksize;
} SqStack;
int InitStack(SqStack &S) {
S.base = (int *)malloc(STACK_INIT_SIZE * sizeof(int));
if (!S.base) exit(OVERFLOW);
S.top = S.base;
S.stacksize = STACK_INIT_SIZE;
return OK;
}
int Push(SqStack &S, int e) {
if (S.top - S.base >= S.stacksize) {
S.base = (int *)realloc(S.base,
(S.stacksize + STACKINCREMENT) * sizeof(int));
if (!S.base) exit(OVERFLOW);
S.top = S.base + S.stacksize;
S.stacksize += STACKINCREMENT;
}
*S.top++ = e;
return OK;
}
int Pop(SqStack &S, int &e) {
if (S.top == S.base) return ERROR;
e = *--S.top;
return OK;
}
int StackEmpty(SqStack S) {
if (S.top == S.base)
return 1;
else
return 0;
}
void conversion(int N, int r) {
SqStack S;
int e;
InitStack(S);
while (N) {
Push(S, N % r);
N = N / r;
}
while (!StackEmpty(S)) {
Pop(S, e);
if (r > 10) {
if (e > 9) {
switch (e) {
case 10:
cout << "A";
break;
case 11:
cout << "B";
break;
case 12:
cout << "C";
break;
case 13:
cout << "D";
break;
case 14:
cout << "E";
break;
case 15:
cout << "F";
break;
default:
break;
}
} else
cout << e;
} else
cout << e;
}
}
int main() {
int N, r;
cout << "请输入一个十进制数:";
cin >> N;
cout << endl;
cout << "请输入要转换的进制数(2,8,10,16):";
cin >> r;
cout << endl;
cout << N << "由十进制转换为:" << r << "进制后的值为:";
conversion(N, r);
cout << endl;
return 0;
}
边栏推荐
猜你喜欢
Iterm2 installation and use
Later discussion on the products (containers) suitable for Zhongke Fangde system
有奖互动|7.19数据库升舱计划实战峰会:行业领袖齐聚,他们因何而来?
What you have to know about responsive layout
Add, delete, change and query operations in JDBC
文件同步工具 rsync 常用选项使用介绍及通过服务同步数据
关于响应式布局,你必须要知道的
uniapp通过addInterceptor拦截路由跳转,控制页面是否需要登录
About the development of chain game system (analysis and description of the principle of smart contract uplink) - Analysis and cases of the development principle of NFT chain game system
无心剑英译吴飞《经纬之歌》
随机推荐
2022河南联赛第(二)场:河南理工大学
What you have to know about responsive layout
深度详解多链钱包系统开发功能及多币种钱包系统开发原理分析
微信小程序获取----onenet的数据并控制stm32的板载LED
【C语言】动态内存管理、柔性数组
The implementation of pytorch in advantageous training
能解决80%故障的排查思路
微信小程序(登录、分享、支付)
PLC-LiSLAM线-面-圆柱体-激光SLAM
Pymongo migrates data from mongodb database
【服务器数据恢复】某品牌ProLiant服务器raid瘫痪,数据库文件丢失,数据库文件备份损坏的数据恢复案例
Feign 最佳实现方案探究
Analysis scaffold
【MATLAB项目实战】基于MATLAB的发票识别(含GUI界面)
Redis 分布式锁的实现
[mindspore] [read graph data] cannot read graph data in mindrecord format
Go Printf 如何进行格式化输出,结构体格式化输出,一站式解决所有烦恼
QGIS拼接瓦片栅格数据
Notes in October 2020
pytorch,初始化tensor