#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(linkstack)
typedef struct node
{
    int data;
    struct node *next;
}linkstack;
linkstack *push(linkstack *top,int x);
void print(linkstack *top);
void main()
{
    linkstack *top=(struct node*)malloc(LEN);
    top->next=NULL;
    top->data=-99;
    int x;             
   printf("请输入数据:");
  scanf("%d",&x);
  top=push(top, x);
//push函数中的传入的top指针,修改其内容是完全OK的;但是修改top指针的地址top=p会没有效果,为了解决这个问题,要用返回值解决问题!!
linkstack
*push(linkstack *top,int x) { linkstack *p; p=(struct node *)malloc(LEN); p->data=x; p->next=top; top=p; return(top); }void print(linkstack *top) { linkstack *t; t=top; while(t->next!=NULL) { printf("%d\t",t->data); t=t->next; } }

 

相关文章:

  • 2021-12-30
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2021-08-31
  • 2021-04-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2021-04-23
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案