|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>
typedef int DataType;
typedef struct Node
{
DataType data;
struct Node * next;
}NODE, * PNODE;
void init_stack(PNODE * top);
bool empty_stack(PNODE top);
int push_stack(PNODE top, DataType e);
void traverse_stack(PNODE top);
int main(void)
{
PNODE S;
DataType val;
init_stack(&S);
empty_stack(S);
push_stack(S, 1);
push_stack(S, 2);
push_stack(S, 3);
push_stack(S, 4);
push_stack(S, 5);
traverse_stack(S);
return 0;
}
void init_stack(PNODE * top)
{
* top = (PNODE)malloc(sizeof(NODE));
if (NULL == * top)
{
printf("fail!!!\n");
exit(-1);
}
else
{
printf("the init is 0K!\n");
(*top)->next = NULL;
}
return;
}
bool empty_stack(PNODE top)
{
if (top->next == NULL)
return true;
else
return false;
}
int push_stack(PNODE top, DataType e)
{
PNODE p = (PNODE )malloc(sizeof(NODE));
if (NULL == p)
exit(-1);
p->data = e;
p->next = top->next;
top->next = p;
return 1;
}
void traverse_stack(PNODE top)
{
if (empty_stack(top))
printf("the stack is empty!\n");
else
{
PNODE p = top->next;
while (p->next != NULL)
{
printf("%d ", p->data);
p = p->next;
}
printf("%d ", p->data);
}
{:1_1:}
printf("\n");
return ;
}
论坛里的朋友能不能帮我看看:如果把红色标记的部分下移那个表情的地方,在VC++编译的时候会报错,是什么原因啊?谢谢。
|
|