搜索
首页 电脑/网络

数据结构中的数制转换问题

就是数据结构中栈和队列的应用问题要有完整的类C语言程序万分急谢

全部回答

2009-05-25

0 0
    你这个需要先自己实现一个stack类,再做一个转换函数。 基本原理如下: N = (N div d)×d + N mod d (其中:div 为整除运算,mod 为求余运算)  因此实现一个函数void conversion(int n, int m)就可以了。
     源码如下: =================华丽的分割线========================== //SeqStack。h文件的内容 using namespace std; const int MaxSize=100; typedef int DataType; //顺序栈类SeqStack的界面 class SeqStack { public: SeqStack(void); //构造函数 ~SeqStack(); void ClearStack(void); //清空栈 void Push(const DataType& x); //压栈 DataType Pop(void); //弹出栈 DataType GetTop(void); //取栈顶元素 bool IsFull(void); //判断栈是否为满 bool IsEmpty(void); //判断栈是否为空 private: int top; DataType s[MaxSize]; }; //顺序栈类的实现 SeqStack::SeqStack(void){ top=-1; } SeqStack::~SeqStack(void){ } void SeqStack::Push(const DataType& x) { if (top==MaxSize-1){ cerr #include"SeqStack。
    h" using namespace std; void conversion(const int n, const int m) { SeqStack stack; DataType temp1; int a,b,count=0; char temp2; b=n; if(m==2||m==8||m==16) { cout0) { a=b%m; b=b/m; stack。
    Push(a),count++; //入栈a,并且count+1,conut用与记数 } for(int i=0;i9 ) { temp2=temp1+55; //将int类型转换为char类型 如10+55=ASCII 65即A 10转换成A cout<<temp2; } else cout<<temp1; } cout<<endl; //转换完后换行 } else { cout<<n<<"不能转换,"; cout<<"转换的进制必须为2,8,16"<<endl; } } 。
    。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
电脑/网络
程序设计
电脑装机
操作系统/系统故障
硬件
笔记本电脑
百度
互联网
反病毒
软件
举报
举报原因(必选):
取消确定举报