|
|
#2
silent_world2012-07-24 17:26
|
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
typedef struct Node
{
int date;
struct Node *pNext;
}NODE, *PNODE;
typedef struct Stack
{
PNODE pTop;
PNODE pBottom;
}STACK, *PSTACK;//PSTACK等价于struct Stack
void init_Stack(STACK pS);
int main(void)
{
STACK S;//STACK等价于struct Stack;
init_Stack(&S);
// pushStack(&S, 1);
// pushStack(&S, 2);
// traverse_Stack(&S);
return 0;
}
void init_Stack(STACK pS)
{
pS->pTop = (PNODE)malloc(sizeof(NODE));
if (NULL == pS->pTop)
{
printf("分配失败!\n");
exit(-1);
}
else
{
pS->pBottom = pS->pTop;
pS->pTop->pNext = NULL;
}
}
程序代码: