1. 程式人生 > >連結串列實現學生資訊表

連結串列實現學生資訊表

#include <stdio.h>
#include <stdlib.h>

void menu()
{
    printf("make your choice \n");
    printf("1:input the information of student\n");
    printf("2:output the information of student \n");
    printf("3:insert one student \n");
    printf("4:delete one information \n");
    printf("5:sort member by number \n");
    printf("other key to quit\n");
};

typedef struct
{
    char name[20];
    int num;
    float grade;
}Student;


typedef struct node
{
    Student s;
    struct node *next;

}Lnode;

void input(Lnode *head)
{
    Lnode *p;
    p=(Lnode*)malloc(sizeof(Lnode));
    printf("input the information (name,number,grade)\n");
    scanf("%s %d %f",&p->s.name,&p->s.num,&p->s.grade);
    p->next=head->next;
    head->next=p;

};

void output(Lnode *head)
{
    head=head->next;
    while(head!=NULL)
        {printf("%s %d %.1f",head->s.name,head->s.num,head->s.grade);
        head=head->next;
        }

}

int main()
{
    Lnode *head;
    int f=1;
    head=(Lnode *)malloc(sizeof(Lnode));
    head->next=NULL;
    while(f)
{
    menu();
    int x;
    scanf("%d",&x);
    switch(x)
    {
        case 1:break;
        case 2:output();break;
        case 3:break;
        case 4:break;
        case 5:break;
        case 6:break;
        default : f=0;
    }

}



    input(head);
    output(head);


    return 0;
}