Home > Back-end >  Novice please help have a look at the code
Novice please help have a look at the code

Time:06-09

# 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:

reference 1st floor proorck2019 response:
void InitStack (LinkStackPtr * L)
It seems to need not add *
Have you added in the typedef


Changed after they lose everything not to come out...

CodePudding user response:

(* L)=(LinkStackPtr) malloc (sizeof (StackNode));
When allocating memory need not * L, L just put directly

CodePudding user response:

reference 4 floor night dew dark mia response:
(* L)=(LinkStackPtr) malloc (sizeof (StackNode));
When allocating memory need not * L, L go directly to


After changed, behind what is not

CodePudding user response:

reference 5 floor dominis reply:
Quote: refer to 4th floor night dew dark mia response:

(* L)=(LinkStackPtr) malloc (sizeof (StackNode));
When allocating memory need not * L, L go directly to


Changed after, behind what they don't have a
L do not add *, add a * after you in brackets LinkStackPtr try

CodePudding user response:

refer to 6th floor night dew dark mia response:
Quote: refer to the 5 floor dominis response:
Quote: refer to 4th floor night dew dark mia response:

(* L)=(LinkStackPtr) malloc (sizeof (StackNode));
When allocating memory need not * L, L go directly to


Changed after, behind what they don't have a
L do not add *, add a * after you in brackets LinkStackPtr try
oh, I can't see structure there has added a *...

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related