Home > Back-end >  Seek advice chain stack data structure () function converts a decimal number to a binary number
Seek advice chain stack data structure () function converts a decimal number to a binary number

Time:11-03

#include
#include
Typedef struct node {
int data;
Struct node * link;
} the NODE;
NODE * push (int m)
{
The NODE * p, * top;
P=(*) malloc (sizeof (NODE));
P - & gt; Data=https://bbs.csdn.net/topics/m;
P - & gt; The link=top;
Top=p;
Return the top;
}
Pop (the NODE is the NODE * * top)
{
NODE * q;
Q=top;
Top=top - & gt; The link;
Free (q);
Return the top;
}
Void conversion (int N, int r)
{
NODE * top1;
Top1=(*) malloc (sizeof (NODE));
Int x=N, y=r;
While (N!=0)
{
Top1=push (N % r);
N=N/r;
}
Printf (" \ n decimal number of % d % d hexadecimal number is: ", x, y);
While (top1!=NULL)
{

Printf (" % d ", top1=pop (top1));
}
printf("\n");
}

Void main ()
{
Int n, r;
Printf (" please input an arbitrary decimal integer and needed to convert hexadecimal number: \ n ");
The scanf (" % d % d ", & amp; N, & amp; R);
Conversion (n, r);
}
  • Related