数据链式存储结构的简单应用 例子

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

(亲供参考)

#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;
}

posted on 2013-01-25 13:29  @ 小浩  阅读(652)  评论(0编辑  收藏  举报