简易学生管理系统

*用链表实现录入学生信息 *

包括学号,姓名, 期末考试成绩

实现功能:(用子函数)

1.学生信息的录入(学号唯一)

2.输出所有的学生信息

3.成绩排序 (降序:从高到低)

4.插入学生信息(按学号插入)

5.按照学号删除。

(1)数据域交换法.a.冒泡法

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef long long DataType;

typedef struct stu

{

    long long num;

    char name[20];

    double score;

    struct stu *next,*head;

} STU;

int linkCnt=0;

STU *head=NULL;

int MenuShow()

{

    printf("*************欢迎使用 万邦易嵌 学生管理系统****************\n");

    printf("  1. 录入学生信息\n");

    printf("  2. 查找学生信息\n");

    printf("  3. 删除学生信息\n");

    printf("  4. 插入学生信息\n");

    printf("  5. 根据学号排序\n");

    printf("  6. 根据成绩排序\n");

    printf("  7. 打印所有学生信息\n");

    printf("  8. 退出\n");

    printf("\n\n请选择:");

    int data;

    scanf("%d", &data);

    return data;

}

STU *Creat_link()

{

    int i,n;

    STU *p;

    static STU*pf;

    printf("请输入输入学生的个数:");

    scanf("%d",&n);

    for(i=0; i<n; i++)

    {

        p=(STU *)malloc(sizeof(STU));

        printf("请输入需要输入的学生信息:");

        scanf("%lld%s%lf",&p->num,p->name,&p->score);//输入数据

        if(i==0)

        {

            head=p;

            pf=p;

            linkCnt++;

        }

        else

        {

            pf->next=p;

            pf=p;

            linkCnt++;

        }

    }

    p->next=NULL;

    return head;

}

void travel()

{

    STU *p = head;

    if(p==NULL)printf("系统中没有学生信息\n");

    printf("学号:     姓名:     成绩:\n");

    while (p != NULL)

    {

        printf("%-10lld%s %10.lf\n", p->num, p->name,p->score);

        p = p->next;

    }

    printf("\n");

}

void find_link()

{

    STU *p=head;

    int num;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要查找的学生学号: ");

    scanf("%d",&num);

    while(p!=NULL)

    {

        if(p->num==num)

        {

            printf("查找成功\n");

            printf("学号:     姓名:     成绩:\n");

            printf("%-10lld %s %10.lf\n", p->num, p->name,p->score);

            return;

        }

        p=p->next;

    }

    printf("学号不存在\n");

}

void del_link()

{

    STU *pt=head,*p,*pf;

    int m;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要删除的学生学号: ");

    scanf("%d",&m);

    while(pt->num!=m&&pt->next!=NULL)

    {

        pf=pt;

        pt=pt->next;

    }

    if(pt->num==m&&pt==head)

    {

        head=pt->next;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next==NULL)

    {

        pf->next=NULL;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next!=NULL&&pt!=head)

    {

        {

            pf->next=pt->next;

            printf("删除成功\n");

            linkCnt--;

            return;

        }

        free(pt);

        pt=NULL;

        printf("空间释放成功!\n");

    }

    else

    {

        printf("查无此人!\n");

    }

}

void insert_link()

{

    STU *p;

    STU *q=head;

    STU *m;

    int n,cnt=0;

    p=(STU *)malloc(sizeof(STU));

    printf("输入插入的位置:");

    scanf("%d",&n);

loop1:

    printf("请输入插入的学生信息:");

    scanf("%lld%s%lf",&p->num,p->name,&p->score);

    m=head;

    while(m!=NULL)

    {

        if(p->num==m->num)

        {

            printf("学号冲突请重新输入!\n");

            goto loop1;

        }

        m=m->next;

    }

    if(m==NULL)

    {

        if(head==NULL)

        {

            head=p;

            p->next=NULL;

            printf("插入成功!\n");

            linkCnt++;

            return;

        }

 

        else if(n==0)

        {

 

 

            p->next=head;

            head=p;

            printf("插入成功!\n");

            linkCnt++;

            return;

 

        }

        else

        {

            while(q->next!=NULL)

            {

                cnt++;

                if(cnt==n)

                {

                    p->next=q->next;

                    q->next=p;

                    printf("插入成功!\n");

                    linkCnt++;

                    return;

                }

                q=q->next;

            }

            if(q->next==NULL&&n>=cnt++)

            {

 

                q->next=p;

                p->next=NULL;

                printf("插入成功!\n");

                linkCnt++;

                return;

            }

        }

    }

}

void  num_link()

{

    STU *p=head,*p1,*p2;

    p1=p;

    p2=p->next;

    long long a;

    char b[20];

    double c;

    int count=0;

   while(p->next!=NULL)

    {

        while(p2!=NULL)

        {

            if(p1->num>p2->num)

            {

                a=p1->num;

                p1->num=p2->num;

                p2->num=a;

 

                strcpy(b,p1->name);

                strcpy(p1->name,p2->name);

                strcpy(p2->name,b);

 

                c=p1->score;

                p1->score=p2->score;

                p2->score=c;

            }

            p2=p2->next;

            p1=p1->next;

        }

        p1=head;

        p2=p1->next;

        p=p->next;

    }

    printf("排序完成!\n");

}

 

void  score_link()

{

    STU *p=head,*p1,*p2;

    p1=p;

    p2=p->next;

    long long a;

    char b[20];

    double c;

    int count=0;

   while(p->next!=NULL)

    {

        while(p2!=NULL)

        {

            if(p1->score>p2->score)

            {

                a=p1->num;

                p1->num=p2->num;

                p2->num=a;

 

                strcpy(b,p1->name);

                strcpy(p1->name,p2->name);

                strcpy(p2->name,b);

 

                c=p1->score;

                p1->score=p2->score;

                p2->score=c;

            }

            p2=p2->next;

            p1=p1->next;

        }

        p1=head;

        p2=p1->next;

        p=p->next;

    }

    printf("排序完成!\n");

}

int main()

{

    int cnt=0;

    while(1)

    {

        char userinfo[100]="我大概是只废喵123456";

        char account[100]= {0};

        char password[100]={0};

        char user[100]={0};

        printf("*****欢迎登入万邦易嵌官方教育系统!******\n");

        printf("请输入账号:");

        gets(account);

        printf("请输入密码:");

        gets(password);

        sprintf(user,"%s%s",account,password);

        if(strcmp(userinfo,user)==0)

        {

            printf("恭喜你,密码正确!\n");

            break;

        }

        else

        {

            printf("密码错误!\n");

            //gets(input);

        }

        ++cnt;

        if(cnt==5)

            exit(cnt);

    }

    int data;

    STU *p;

    while(1)

    {

        data = MenuShow();

        switch (data)

        {

        case 1:

            p=Creat_link();

            break;

        case 2:

            find_link();

            break;

        case 3:

            del_link();

            break;

        case 4:

            insert_link();

            break;

        case 5:

            num_link();

            break;

        case 6:

            score_link();

            break;

        case 7:

            travel();

            break;

        case 8:

            printf("系统成功退出!\n");

            return 0; //结束主函数

        }

    }

    return 0;

}

(2).b.头累加法

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef long long DataType;

typedef struct stu

{

    long long num;

    char name[20];

    double score;

    struct stu *next,*head;

} STU;

int linkCnt=0;

STU *head=NULL;

int MenuShow()

{

    printf("*************欢迎使用 万邦易嵌 学生管理系统****************\n");

    printf("  1. 录入学生信息\n");

    printf("  2. 查找学生信息\n");

    printf("  3. 删除学生信息\n");

    printf("  4. 插入学生信息\n");

    printf("  5. 根据学号排序\n");

    printf("  6. 根据成绩排序\n");

    printf("  7. 打印所有学生信息\n");

    printf("  8. 退出\n");

    printf("\n\n请选择:");

    int data;

    scanf("%d", &data);

    return data;

}

STU *Creat_link()

{

    int i,n;

    STU *p;

    static STU*pf;

    printf("请输入输入学生的个数:");

    scanf("%d",&n);

    for(i=0; i<n; i++)

    {

        p=(STU *)malloc(sizeof(STU));

        printf("请输入需要输入的学生信息:");

        scanf("%lld%s%lf",&p->num,p->name,&p->score);//输入数据

        if(i==0)

        {

            head=p;

            pf=p;

            linkCnt++;

        }

        else

        {

            pf->next=p;

            pf=p;

            linkCnt++;

        }

    }

    p->next=NULL;

    return head;

}

void travel()

{

    STU *p = head;

    if(p==NULL)printf("系统中没有学生信息\n");

    printf("学号:     姓名:     成绩:\n");

    while (p != NULL)

    {

        printf("%-10lld%s %10.lf\n", p->num, p->name,p->score);

        p = p->next;

    }

    printf("\n");

}

void find_link()

{

    STU *p=head;

    int num;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要查找的学生学号: ");

    scanf("%d",&num);

    while(p!=NULL)

    {

        if(p->num==num)

        {

            printf("查找成功\n");

            printf("学号:     姓名:     成绩:\n");

            printf("%-10lld %s %10.lf\n", p->num, p->name,p->score);

            return;

        }

        p=p->next;

    }

    printf("学号不存在\n");

}

void del_link()

{

    STU *pt=head,*p,*pf;

    int m;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要删除的学生学号: ");

    scanf("%d",&m);

    while(pt->num!=m&&pt->next!=NULL)

    {

        pf=pt;

        pt=pt->next;

    }

    if(pt->num==m&&pt==head)

    {

        head=pt->next;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next==NULL)

    {

        pf->next=NULL;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next!=NULL&&pt!=head)

    {

        {

            pf->next=pt->next;

            printf("删除成功\n");

            linkCnt--;

            return;

        }

        free(pt);

        pt=NULL;

        printf("空间释放成功!\n");

    }

    else

    {

        printf("查无此人!\n");

    }

}

void insert_link()

{

    STU *p;

    STU *q=head;

    STU *m;

    int n,cnt=0;

    p=(STU *)malloc(sizeof(STU));

    printf("输入插入的位置:");

    scanf("%d",&n);

loop1:

    printf("请输入插入的学生信息:");

    scanf("%lld%s%lf",&p->num,p->name,&p->score);

    m=head;

    while(m!=NULL)

    {

        if(p->num==m->num)

        {

            printf("学号冲突请重新输入!\n");

            goto loop1;

        }

        m=m->next;

    }

    if(m==NULL)

    {

        if(head==NULL)

        {

            head=p;

            p->next=NULL;

            printf("插入成功!\n");

            linkCnt++;

            return;

        }

 

        else if(n==0)

        {

 

 

            p->next=head;

            head=p;

            printf("插入成功!\n");

            linkCnt++;

            return;

 

        }

        else

        {

            while(q->next!=NULL)

            {

                cnt++;

                if(cnt==n)

                {

                    p->next=q->next;

                    q->next=p;

                    printf("插入成功!\n");

                    linkCnt++;

                    return;

                }

                q=q->next;

            }

            if(q->next==NULL&&n>=cnt++)

            {

 

                q->next=p;

                p->next=NULL;

                printf("插入成功!\n");

                linkCnt++;

                return;

            }

        }

    }

}

void  num_link()

{

    STU *p=head;

    STU *pf=head;

    int i;

    printf("系统中已有的学生为%d个\n", linkCnt);

    if(head==NULL) printf("系统中没有录入学生信息!\n");

    else if(head->next==NULL)//只有一个学生

    {

        printf("排序成功!\n");

        return ;

        //printf("%-8d %s %12.1f\n", p->num, p->name, p->score);

    }

    else//至少有两个学生

    {

        for(i=1; i<linkCnt; )

        {

            pf=p;

            p=p->next;

            if(pf->num<p->num) i++;

            if(pf->num>p->num)

            {

                pf->next=p->next;

                p->next=head;

                head=p;

                i=1;

            }

        }

        printf("排序成功!\n");

    }

}

void  score_link()

{

    STU *p=head;

    STU *pf=head;

    int i;

    printf("系统中已有的学生为%d个\n",linkCnt);

    if(head==NULL) printf("系统中没有录入学生信息!\n");

    else if(head->next==NULL)

    {

        printf("排序成功!\n");

        return ;

    }

    else

    {

        for(i=1; i<linkCnt; )

        {

            pf=p;

            p=p->next;

            if(pf->score<p->score) i++;

            if(pf->score>p->score)

            {

                pf->next=p->next;

                p->next=head;

                head=p;

                i=1;

            }

        }

        printf("排序成功!\n");

    }

}

int main()

{

   int cnt=0;

    while(1)

    {

        char userinfo[100]="我大概是只废喵123456";

        char account[100]= {0};

        char password[100]={0};

        char user[100]={0};

        printf("*****欢迎登入万邦易嵌官方教育系统!******\n");

        printf("请输入账号:");

        gets(account);

        printf("请输入密码:");

        gets(password);

        sprintf(user,"%s%s",account,password);

        if(strcmp(userinfo,user)==0)

        {

            printf("恭喜你,密码正确!\n");

            break;

        }

        else

        {

            printf("密码错误!\n");

            //gets(input);

        }

        ++cnt;

        if(cnt==5)

            exit(cnt);

    }

    int data;

    STU *p;

    while(1)

    {

        data = MenuShow();

        switch (data)

        {

        case 1:

            p=Creat_link();

            break;

        case 2:

            find_link();

            break;

        case 3:

            del_link();

            break;

        case 4:

            insert_link();

            break;

        case 5:

            num_link();

            break;

        case 6:

            score_link();

            break;

        case 7:

            travel();

            break;

        case 8:

            printf("系统成功退出!\n");

            return 0; //结束主函数

        }

    }

    return 0;

}

(3)指针域交换法

#include<stdio.h>

#include<stdlib.h>

struct STU

{

       int num;

       char name[10];

       float score;

 

       struct STU *pnext;

       struct STU *pf;

};

 

struct STU * Creat_link();

void Pri_link(struct STU *phead);

struct STU * Search_link(struct STU *phead);

struct STU * Sort_num(struct STU *phead);

struct STU * Sort_score(struct STU *phead);

 

int main()

{

       struct STU *phead;

       phead=Creat_link();

       Pri_link(phead);

       phead=Sort_score(phead);

       Pri_link(phead);

       return 0;

}

 

//创建链表

struct STU * Creat_link()

{

       int n,i;

       struct STU *phead,*p,*pf;

       printf("输入结点个数:");

       scanf("%d",&n);

 

       for(i=1;i<=n;i++)

       {

              p=(struct STU*)malloc(sizeof(struct STU));

              printf("输入第%d个人的信息:",i);

              scanf("%d %s %f",&p->num,p->name,&p->score);

              if(i==1)

              {

                     phead=p;

                     pf=p;

              }

              else

              {

                     pf->pnext=p;

 

                     pf=p;

              }

       }

       p->pnext=NULL;

       return phead;

}

 

//遍历链表

void Pri_link(struct STU *phead)

{

       struct STU *pt=phead;

       printf("\n输出数据:\n");

       while(pt!=NULL)

       {

              printf("%d  %s  %f\n",pt->num,pt->name,pt->score);

              pt=pt->pnext;

       }

 

}

 

//查询

struct STU * Search_link(struct STU *phead)

{

       struct STU *pt=phead;

       int num;

       printf("输入要查找的学号:");

       scanf("%d",&num);

 

       if(phead==NULL)

       {

              printf("链表为空!\n");

       }

       else

       {

              while(pt->num!=num && pt->pnext!=NULL)

              {

                     pt=pt->pnext;

              }

              if(pt->num==num)

              {

                     printf("所要查找人的信息如下:");

                     printf("%d  %s  %f\n",pt->num,pt->name,pt->score);

              }

              else

              {

                     printf("查无此人!");

              }

       }

       return pt;

}

 

struct STU *Del_link(struct STU *phead)

{

       int num;

       struct STU *pt=phead,*pf;

       printf("输入要删除的学号:");

       scanf("%d",&num);

 

       if(phead==NULL)

       {

              printf("链表为空!\n");

       }

       else

       {

              while(pt->num!=num && pt->pnext!=NULL)

              {

                     pf=pt;

                     pt=pt->pnext;

              }

              if(pt->num==num)

              {

                     if(pt==phead)

                     {

                            phead=pt->pnext;

                     }

                     else if(pt->pnext==NULL)

                     {

                            pf->pnext=NULL;

                     }

                     else

                     {

                            pf->pnext=pt->pnext;

                     }

                     printf("找到此人!\n");

                     free(pt);

                     pt=NULL;

                     printf("空间释放成功!\n");

              }

              else

              {

                     printf("查无此人!");

              }

       }

       return phead;

}

 

//成绩排序

struct STU *  Sort_score(struct STU *phead)

{

       struct STU *pt=phead,*pf,*p,*pm,*ph=phead;

       int i,j,n=0;

       while(ph!=NULL)

       {

              n++;

              ph=ph->pnext;

       }

       printf("n=%d\n",n);

       for(i=1;i<=n;i++)

       {

              pm=pf=pt=phead;

              while(pt->pnext!=NULL)

              {

                     pm=pf;

                     pf=pt;

                     pt=pt->pnext;

                     if(pf->score< pt->score)

                     {

                            if(pf==phead)

                            {

                                   pf->pnext=pt->pnext;

                                   pt->pnext=pf;

                                   p=pf;

                                   pf=pt;

                                   pt=p;

                                   phead=pf;

                            }

                            else

                            {

                                   pf->pnext=pt->pnext;

                                   pt->pnext=pf;

                                   pm->pnext=pt;

                                   p=pf;

                                   pf=pt;

                                   pt=p;

                            }

                     }

              }

       }

       return phead;

}

 

//学号排序

struct STU * Sort_num(struct STU *phead)

{

       struct STU *pt=phead,*pf,*p,*pm,*ph=phead;

       int i,j,n=0;

       while(ph!=NULL)

       {

              n++;

              ph=ph->pnext;

       }

       printf("n=%d\n",n);

       for(i=1;i<=n;i++)

       {

              pm=pf=pt=phead;

              while(pt->pnext!=NULL)

              {

                     pm=pf;

                     pf=pt;

                     pt=pt->pnext;

                     if(pf->num > pt->num)

                     {

                            if(pf==phead)

                            {

                                   pf->pnext=pt->pnext;

                                   pt->pnext=pf;

                                   p=pf;

                                   pf=pt;

                                   pt=p;

                                   phead=pf;

                            }

                            else

                            {

                                   pf->pnext=pt->pnext;

                                   pt->pnext=pf;

                                   pm->pnext=pt;

                                   p=pf;

                                   pf=pt;

                                   pt=p;

                            }

                     }

              }

       }

       return phead;

}

struct STU *insert_link(struct STU *phead)

{

       struct STU *p,*pf,*pt=phead;

       p=(struct STU *)malloc(sizeof(struct STU));

       printf("输入要插入的数据:");

       scanf("%d %s %f",&p->num,p->name,&p->score);

 

       if(phead=NULL)

       {

              phead=p;

              p->pnext=NULL;

       }

       else

       {

              while(p->num > pt->num && pt->pnext!=NULL)

              {

                     pf=pt;

                     pt=pt->pnext;

              }

              if(p->num < pt->num)

              {

                     if(pt==phead)

                     {

                            p->pnext=phead;

                            phead=p;

                     }

                     else

                     {

                            p->pnext=pt;

                            pf->pnext=p;

                     }

              }

              else

              {

                     pt->pnext=p;

                     p->pnext=NULL;

              }

 

       }

       return phead;

}

(4)双向链表法

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef long long DataType;

typedef struct stu

{

    long long num;

    char name[20];

    double score;

    struct stu *next,*head,*prev;

} STU;

int linkCnt=0;

STU *head=NULL;

int MenuShow()

{

    printf("*************欢迎使用 万邦易嵌 学生管理系统****************\n");

    printf("  1. 录入学生信息\n");

    printf("  2. 查找学生信息\n");

    printf("  3. 删除学生信息\n");

    printf("  4. 插入学生信息\n");

    printf("  5. 根据学号排序\n");

    printf("  6. 根据成绩排序\n");

    printf("  7. 打印所有学生信息\n");

    printf("  8. 退出\n");

    printf("\n\n请选择:");

    int data;

    scanf("%d", &data);

    return data;

}

STU *Creat_link()

{

    int i,n;

    STU *p;

    static STU*pf;

    printf("请输入输入学生的个数:");

    scanf("%d",&n);

    for(i=0; i<n; i++)

    {

        p=(STU *)malloc(sizeof(STU));

        printf("请输入需要输入的学生信息:");

        scanf("%lld%s%lf",&p->num,p->name,&p->score);//输入数据

        if(i==0)

        {

            head=p;

            p->next=NULL;

            p->prev=NULL;

            pf=p;

            linkCnt++;

        }

        else

        {

            pf->next=p;

            p->prev=pf;

            pf=p;

            linkCnt++;

        }

    }

    p->next=NULL;

    return head;

}

void travel()

{

    STU *p = head;

    if(p==NULL)printf("系统中没有学生信息\n");

    printf("学号:     姓名:     成绩:\n");

    while (p != NULL)

    {

        printf("%-10lld%s %10.lf\n", p->num, p->name,p->score);

        p = p->next;

    }

    printf("\n");

}

void find_link()

{

    STU *p=head;

    int num;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要查找的学生学号: ");

    scanf("%d",&num);

    while(p!=NULL)

    {

        if(p->num==num)

        {

            printf("查找成功\n");

            printf("学号:     姓名:     成绩:\n");

            printf("%-10lld %s %10.lf\n", p->num, p->name,p->score);

            return;

        }

        p=p->next;

    }

    printf("学号不存在\n");

}

void del_link()

{

    STU *pt=head,*p,*pf,*pp;

    int m;

    if(head==NULL)

    {

        printf("系统中没有学生信息\n");

        return;

    }

    printf("请输入需要删除的学生学号: ");

    scanf("%d",&m);

    while(pt->num!=m&&pt->next!=NULL)

    {

        pf=pt;

        pt=pt->next;

        pt->prev=pf;

    }

    if(pt->num==m&&pt==head&&p->next==NULL)

    {

        head=NULL;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt==head&&pt->next!=NULL)

    {

        head=pt->next;

        pt->prev=NULL;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next==NULL)

    {

        pf->next=NULL;

        printf("删除成功\n");

        linkCnt--;

        return;

    }

    else if(pt->num==m&&pt->next!=NULL&&pt!=head)

    {

        {

            pp=pt->next;

            pf->next=pp;

            pp->prev=pf;

            printf("删除成功\n");

            linkCnt--;

            return;

        }

        free(pt);

        pt=NULL;

        printf("空间释放成功!\n");

    }

    else

    {

        printf("查无此人!\n");

    }

}

void insert_link()

{

    STU *p;

    STU *q=head;

    STU *m;

    int n,cnt=0;

    p=(STU *)malloc(sizeof(STU));

    printf("输入插入的位置:");

    scanf("%d",&n);

loop1:

    printf("请输入插入的学生信息:");

    scanf("%lld%s%lf",&p->num,p->name,&p->score);

    m=head;

    while(m!=NULL)

    {

        if(p->num==m->num)

        {

            printf("学号冲突请重新输入!\n");

            goto loop1;

        }

        m=m->next;

    }

    if(m==NULL)

    {

        if(head==NULL)

        {

            head=p;

            p->next=NULL;

            p->prev=NULL;

            printf("插入成功!\n");

            linkCnt++;

            return;

        }

 

        else if(n==0)

        {

 

 

            p->next=head;

            p->prev=NULL;

            head=p;

            printf("插入成功!\n");

            linkCnt++;

            return;

 

        }

        else

        {

            while(q->next!=NULL)

            {

                cnt++;

                if(cnt==n)

                {

                    p->next=q->next;

                    p->prev=p;

                    q->next=p;

                    printf("插入成功!\n");

                    linkCnt++;

                    return;

                }

                q=q->next;

            }

            if(q->next==NULL&&n>=cnt++)

            {

 

                q->next=p;

                p->prev=q;

                p->next=NULL;

                printf("插入成功!\n");

                linkCnt++;

                return;

            }

        }

    }

}

void  num_link()

{

    STU *p=head,*p1,*p2;

    p1=p;

    p2=p->next;

    p1=p2->prev;

    long long a;

    char b[20];

    double c;

    int count=0;

   while(p->next!=NULL)

    {

        while(p2!=NULL)

        {

            if(p1->num>p2->num)

            {

                a=p1->num;

                p1->num=p2->num;

                p2->num=a;

 

                strcpy(b,p1->name);

                strcpy(p1->name,p2->name);

                strcpy(p2->name,b);

 

                c=p1->score;

                p1->score=p2->score;

                p2->score=c;

            }

            p2=p2->next;

            p1=p1->next;

        }

        p1=head;

        p1->prev=NULL;

        p2=p1->next;

        p1=p2->prev;

        p=p->next;

    }

    printf("排序完成!\n");

}

void  score_link()

{

    STU *p=head,*p1,*p2;

    p1=p;

    p2=p->next;

    p1=p2->prev;

    long long a;

    char b[20];

    double c;

    int count=0;

   while(p->next!=NULL)

    {

        while(p2!=NULL)

        {

            if(p1->score>p2->score)

            {

                a=p1->num;

                p1->num=p2->num;

                p2->num=a;

 

                strcpy(b,p1->name);

                strcpy(p1->name,p2->name);

                strcpy(p2->name,b);

 

                c=p1->score;

                p1->score=p2->score;

                p2->score=c;

            }

            p2=p2->next;

            p1=p1->next;

        }

        p1=head;

        p1->prev=NULL;

        p2=p1->next;

        p1=p2->prev;

        p=p->next;

    }

    printf("排序完成!\n");

}

int main()

{

    int cnt=0;

    while(1)

    {

        char userinfo[100]="我大概是只废喵123456";

        char account[100]= {0};

        char password[100]={0};

        char user[100]={0};

        printf("*****欢迎登入万邦易嵌官方教育系统!******\n");

        printf("请输入账号:");

        gets(account);

        printf("请输入密码:");

        gets(password);

        sprintf(user,"%s%s",account,password);

        if(strcmp(userinfo,user)==0)

        {

            printf("恭喜你,密码正确!\n");

            break;

        }

        else

        {

            printf("密码错误!\n");

            //gets(input);

        }

        ++cnt;

        if(cnt==5)

            exit(cnt);

    }

    int data;

    STU *p;

    while(1)

    {

        data = MenuShow();

        switch (data)

        {

        case 1:

            p=Creat_link();

            break;

        case 2:

            find_link();

            break;

        case 3:

            del_link();

            break;

        case 4:

            insert_link();

            break;

        case 5:

            num_link();

            break;

        case 6:

            score_link();

            break;

        case 7:

            travel();

            break;

        case 8:

            printf("系统成功退出!\n");

            return 0; //结束主函数

        }

    }

    return 0;

}

posted @ 2017-08-16 21:20  我大概是只废喵  阅读(242)  评论(0编辑  收藏  举报