Home >
Back-end > Novice please help have a look at the code
Novice please help have a look at the code
# include
# include
Typedef struct StackNode
{
The int data;
Struct StackNode * next;
} StackNode, * LinkStackPtr;
Void InitStack (LinkStackPtr * L)
{
(* L)=(LinkStackPtr) malloc (sizeof (StackNode));
if(!
(* L).Printf (" allocation failure \ n ");
The else
(* L) - & gt; Next=NULL;
}
Void Push (LinkStackPtr * L, int e)
{
LinkStackPtr p;
P=(StackNode *) malloc (sizeof (StackNode));
P - & gt; data=https://bbs.csdn.net/topics/e;
P - & gt; Next=(* L) - & gt; Next;
(* L) - & gt; Next=p;
}
Pop (LinkStackPtr is void * L, int * e)
{
StackNode * p;
P=* L;
If ((* L) - & gt; Next==NULL)
Printf (" stack is empty ");
The else
{
* e=(* L) - & gt; Next - & gt; data;
P=(* L) - & gt; Next;
Free (p);
}
}
Void conversion ()
{
Int N, f, e;
LinkStackPtr s;
InitStack (& amp; S);
Printf (" please input to convert hexadecimal number \ n ");
The scanf (" % d ", & amp; N);
Printf (" please input to convert hexadecimal \ n ");
The scanf (" % d ", & amp; F);
While (N)
{
Int h;
H=N % f;
Push (& amp; S, h);
N=N/f;
}
While (s!=NULL)
{
Pop (& amp; S, & amp; E);
Printf (" % d ", e);
}
}
Void main ()
{
Conversion ();
}
CodePudding user response:
Void InitStack (LinkStackPtr * L)
It seems to need not add *
Have you added in the typedef CodePudding user response:
StackNode, * LinkStackPt;
The former is a structure type and the latter is a structure pointer type CodePudding user response: