快捷搜索:

十进制数向其他进制转换代码

此例题的实现目的是经由过程栈布局来实现十进制数向其他进制转换,不是很难,应该都能看懂吧。

#include\"iostream.h\"

#include\"math.h\"

#include

typedef struct node

{

int data;

node * next;

}Node;

classShuZhiZhuanHuan

{

public:

void ZhuanHuan(int d,int i);

void print();

private:

Node *top;

};

void ShuZhiZhuanHuan::ZhuanHuan(int d,int i)

{

int m,n=0;

Node * p;

while(d>0)

{

m=d%i;

d=d/i;

p=new Node;

if(!n)

{

p->data=m;

top=p;

top->next=NULL;

n++;

}

else{

p->data=m;

p->next=top;

top=p;

}

}

}

voidShuZhiZhuanHuan::print()

{

Node *p;

while(top!=NULL )

{

p=top;

if(p->data>9)

coutnext;

delete p;

}

}

void main()

{

cout>a>>b;

ShuZhiZhuanHuan shuzhizhuanhuan;

shuzhizhuanhuan.ZhuanHuan(a,b);

shuzhizhuanhuan .print();

cout<<\'\\n\'<<\"感谢应用!\"

getch();

}

您可能还会对下面的文章感兴趣: