1. 程式人生 > >動態連結串列的建立(程式碼)

動態連結串列的建立(程式碼)

/*** 動態連結串列的建立 ***/
#include<stdio.h>
#include<stdlib.h>
#define ID struct Student
#define LEN sizeof(ID)    //該巨集定義為後續結構體的使用提供便捷
ID * creative( int );     //子函式申明
ID
{
    int num;
    int score;
    ID * next;
};     //結構體申明

int main(void)
{
    int n;
    printf(" Enter the n  "
        ", n = \n");     //printf() 的一種表示方法,C primer plus中介紹

    scanf("%d",&n);
    printf(" Piease waiting .....\n");
    ID * p = creative(n);    //p存放返回的首地址
    printf(" 現在開始輸出成績 \n");
    while( p->next != NULL )
    {
        printf("%d %d\n", p->num , p->score );
        p = p->next;
    }
    printf("%d %d\n", p->num , p->score );
    printf(" OK! \n");