数据结构中链式栈的简单应用例子:

(亲供参考)

#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
struct Student{
 int data;
 struct Student *next;
};

int main()

   struct Student *head,*p;
   head=p=(struct Student *)malloc(sizeof(struct Student));
   p->next=NULL;
   int n;
   printf("请输入你要输入数据的个数:\n");
   scanf("%d",&n);
   while(n--)
   {
    cin>>p->data;
    p->next=(struct Student *)malloc(sizeof(struct Student));
    p=p->next;
    p->next=NULL;
      
   }
  
   p=head;
   while(p->next!=NULL)   
   {
    cout<<p->data<<endl;
    p=p->next;
   }

   return 0;
}

相关文章:

  • 2021-07-27
  • 2021-11-07
  • 2021-12-23
  • 2021-05-26
  • 2021-12-03
  • 2022-12-23
  • 2021-11-09
  • 2021-09-12
猜你喜欢
  • 2021-12-06
  • 2021-06-09
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案