回复 3楼 westfall999
程序代码:
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define bool int;
#define true 1;
#define false 0;
typedef struct Node
{
int date;
struct Node *pNext;
}NODE, *PNODE;
typedef struct Stack
{
PNODE pTop;
PNODE pBottom;
}STACK, *PSTACK;
void init_Stack(PSTACK);
void push(PSTACK pS, int Val);
void traverse(PSTACK);
bool pop(PSTACK, int *);
int main()
{
STACK S;
//int val;
init_Stack(&S);
push(&S, 1);
push(&S, 2);
push(&S, 3);
push(&S, 4);
push(&S, 5);
traverse(&S);
return 0;
}
void init_Stack(PSTACK pS)
{
pS->pTop = (PNODE)malloc(sizeof(NODE));
if (NULL == pS->pTop)
{
printf("动态内存分配失败!\n");
exit(-1);
}
else
{
pS->pBottom = pS->pTop;
pS->pBottom->pNext = NULL;
}
}
void push(PSTACK pS, int val)
{
PNODE pNew = (PNODE)malloc(sizeof(NODE));
pNew->date = val;
pNew->pNext = pS->pTop;
pS->pTop = pNew;
return;
}
void traverse(PSTACK pS)
{
PNODE p = pS->pTop;
while (p != pS->pBottom)
{
printf("%d ", p->date);
p = p->pNext;
}
printf("\n");
return;
}
bool empty(PSTACK pS)
{
if (pS->pTop == pS->pBottom)
return true;
else
return false;
}
bool pop(PSTACK pS, int *pVal)
{
if ( empty(pS) )
{
return false;
}
else
{
PNODE r = pS->pTop;
*pVal = r->date;
pS->pTop = r->pNext;
free(r);
r = NULL;
return true;
}
}
//红色的那名在编译的时候提示warning C4091: ' ' : ignored on left of 'int ' when no variable is declared这个错误,我检查不知道哪里出错误,麻烦帮忙解决