数据结构中链式栈的简单应用例子:
(亲供参考)
#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;
}