数据链式存储结构的简单应用 例子
数据结构中链式栈的简单应用例子:
(亲供参考)
#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;
}
联系方式
 
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号