标题:求帮忙改错!拜托.....
取消只看楼主
whxych
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2014-4-14
结帖率:100%
已结贴  问题点数:20 回复次数:0 
求帮忙改错!拜托.....
# include<stdio.h>
# include<malloc.h>
typedef struct snode*slink;
typedef struct snode{int element;slink next;}
StackNode;
typedef struct lstack*Stack;
typedef struct lstack{
     slink top;
}Lstack;
   Stack StackInit()
{
   Stack S=(Lstack*)malloc(sizeof*S);
   S->top=0;
   return S;
}
  slink NewStackNode()
{
  slink p;
  if((p=((StackNode*)malloc(sizeof(StackNode)))==0
  printf ("ERROR")
else
  return p;
}
  int StackFull(Stack S)
{
  slink p;
  if((p=(StackNode*)malloc(sizeof(StackNode)))==0)
  return 1;
else
{
    free(p);
    return 0;
}
}
  int StackEmpty(Stack S)
  {
  slink p;
  if(StackFull(S))
    printf("Stack is full");
  p=NewStackNode();
  p->element=x;
  p->next=S->top;
  S->top=p;
  }
  int pop(Stack S)
  {
      slink p;
      int x;
      if(StackEmpty(s))
          printf("Stack is empty");
      x=S->top->element;
      p=S->top;
      S->top=->next;
      free (p);
      return x;
  }
  StackItem StackTop(Stack S)
  {
      if(StackEmoty(S))Error("Stack is empty");
      else return S->top->element;
  }
  void main()
  {
  int i,x,a,b,c;
  Lstack L;
  Stack S=&L;
  StackInit();
  printf("从键盘输入4个入栈的值:")
  for(i=0;i<4;i++)
  {
   scanf("%d",&x);
   push(x,S);
  }
  printf("栈顶元素为:%d\n",StackTop(S))
  a=pop(S)
  b=pop(S)
  c=pop(S)
  push(a,S)
  printf("栈顶元素为:%d\n",StackTop(S))
  }
搜索更多相关主题的帖子: element include return 
2014-04-14 19:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-430085-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.723543 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved