Home > Back-end >  Stack output is wrong
Stack output is wrong

Time:11-03

#include
#include
using namespace std;

Struct LinkstNode
{
int data;
LinkstNode * next;
};

Void InitStack (LinkstNode * & amp; S)
{
S=(LinkstNode *) malloc (sizeof (LinkstNode));
s-> Next=NULL;
}

Void Push (LinkstNode * & amp; S, int a [], int n)
{
LinkstNode * p;
P=(LinkstNode *) malloc (sizeof (LinkstNode));
for(int i=0; i{
P - & gt; data=https://bbs.csdn.net/topics/a [I];
P - & gt; Next=s - & gt; Next;
s-> Next=p;
}
}

Void DispStack (LinkstNode * s, int n)
{
Int a [n].
for(int i=0; i{
A [I]=s - & gt; next-> The data;
S=s - & gt; Next;
cout}
cout<& lt;" "Standing order & lt;
}

The main ()
{
,4,5,1 int a [4]={2};
Int n=4;
LinkstNode * s;
InitStack (s);
Push (s, a, n);
DispStack (s, n);
}


  • Related