簡單靜態連結串列
阿新 • • 發佈:2019-02-12
下面的程式碼是一個簡單的靜態連結串列,它是由3個學生的資料組成的(學號,成績)的結點組成。
#include<iostream> #include<stdio.h> using namespace std; struct student { long num; float score; struct student * next; //該指標指向student型別的結構體 }; //必須有分號 int main() { struct student a,b,c,*head,*p; a.num=16010; a.score=89.5; //賦值 b.num=16011; b.score=98; c.num=16012; c.score=94; head=&a; //將a的地址給head a.next=&b; b.next=&c; c.next=NULL; p=head; do //輸出記錄 { cout<<p->num<<" "<<p->score<<endl; p=p->next; }while(p!=NULL); getchar(); }