注册 登录
编程论坛 数据结构与算法

数据结构的课程设计

小不点。丫头 发布于 2012-06-10 16:00, 929 次点击
主要的算法是:
初始链表的建立;
对链表按总分降序排序;
排名次;
主函数;
"我没有做出来做一半的";
# include <stdlib.h>
#include<malloc.h>
#include <string.h>
typedef struct student
    {  char num[6];
       char name[8];
        int tax;
        int english ;
        int math;
        int score;
        struct student *next;
    }jd;
jd *h,*head1,*end,*head,*r[];
output( jd *head1)
    {
        jd *q;
        q=head1->next;
        while(q!=NULL)
        {
            printf("%s\t\t%s\t\t%d\t\t%d\n",q->num,q->name,q->english,q->math);
            q=q->next;
        }
        printf("\n");
    }
foutput(jd *head1)
    {
        FILE *fp1;
        jd *q;
        fp1=fopen("student.txt","w");
        if(fp1==NULL)
        {
            printf("无法打开文件!\n");
            exit(0);
        }
        q=head->next;
        while(q!=NULL)
        {
            fprintf(fp1,"%s\t\t%s\t\t%d\t\t%d\n",q->num,q->name,q->english,q->math);
            q=q->next;
        }
        fclose(fp1);
    }                  
               
creat()
    {    jd *end,*p;
        FILE *fp;
        fp=fopen("student.txt","r"); //以只读方式打开当前目录下的家庭图书信息.txt
        if(fp==NULL)
        {
            printf("无法打开文件");
            exit(0);    //-------- 终止程序 ---------
        }
        h=(jd *)malloc(sizeof(jd));
        end=h;
        end->next=NULL;
        while(!feof(fp)) //------!feof(fp)值为0,不在执行循环语句  ------
        {
            p=(jd *)malloc(sizeof(jd));
            fscanf(fp,"%s%s%d%d\n",&p->num,&p->name,&p->english,&p->math);
            p->next=NULL;
            end->next=p;
            end=p;
        }
        output (h);
        fclose(fp);//----关闭文件-----
 peixu()
    {
        int m,n;                                    
        char num[6];
        creat();
        printf("请输入学号:");
        scanf("%s",&num);
        p=h->next;
        while(p!=NULL)
        {
            if(strcmp(num,p->num)==0)
            {
                p->score=p->english+p->math;
            }
            p=p->next;
        }
        output(p);
    }
 void insert_sort(jd *r[],int n)
 {  int i,j;
    for(i=2;i<n;i++)
    {  r[0]=r[i];
       j=i-1;
       while(r[0].score<r[i].score)
       {
           r[j++]=r[j];
           j--;

       }
       r[j+1]=r[0];
    }
 }

 main()
    { int n;
       printf("\t  欢迎使用成绩排名管理系统!\n\n");
      while(1)
         { printf("\t    成绩排名管理系统程序\n\n");
                printf("================我的菜单====================\n");
                printf("\t  1.链表的建立\n");
                printf("\t  2.对链表按总分降序排序\n");
                printf("\t  3.对成绩表排名次\n");
                printf("\t  0.退出\n");
                printf("============================================\n");
                printf("\t\t请选择:");
                scanf("%d",&n);
             if((n>=0) && (n<=2))
             {  switch(n)
                {   
                    case 1:creat();break;
                    case 2:insert_sort();break;
                    case 0:exit(0);
                }
             printf("\n操作完毕,请再次选择\n!");
             }
          else
          printf("感谢您的使用!!!\n\n");
         }
    }
5 回复
#2
小不点。丫头2012-06-10 16:01
希望大家帮忙看看啊
#3
小虎虎2012-06-11 16:44
刚学,不太会
#4
gao1143299762012-06-12 15:22
你只是用链表来排序吗
#5
海阔天空!2012-06-25 21:23
呵呵呵,数据结构是要学好
#6
海阔天空!2012-06-25 21:24
数据结构和算法很重要的

1