章子扬作业

编程入门 行业动态 更新时间:2024-10-07 12:20:21

<a href=https://www.elefans.com/category/jswz/34/1767274.html style=章子扬作业"/>

章子扬作业

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

int main(int argc, const char *argv[])
{
    int m;
    zzy *l=create();
    if(NULL==l)
    {
        return -2;
    }
    printf("创建成功\n");
    while(1)
    {
        printf("-----学生管理系统-----");
        printf("1.输入学生信息");
        printf("2.按成绩查找学生");
        printf("3.删除学生");
        printf("4.按学生成绩排序");
        printf("5.退出");
        printf("6.");
        scanf("%d",&m);
        datatype1 name1[20];
        datatype score1;
        int n,i;
            switch(m)
            {
        case 1:
                printf("输入几位学生信息:");
                scanf("%d",&n);
                for(i=1;i<=n;i++)
                {
                    printf("请输入学生信息:");
                    scanf("%s%d",name1,&score1);
                    put(l,score1,name1);
                }
                bian(l);
                break;
        case 2:
                printf("请输入查找的学生成绩:");
                scanf("%d",&score1);
                chazhao(l,score1);
                break;
        case 3:
                printf("请输入想删除的学生的学生成绩:");
                scanf("%d",&score1);
                shang(l,score1);
                bian(l);
                break;
        case 4:
                paixu(l);
                bian(l);
                break;
        case 5:exit(0);
        }
        }


    return 0;
}

#ifndef __ZZY_H__
#define __ZZY_H__

typedef int datatype;
typedef char datatype1;
typedef struct node
{

    datatype1 name[20];
    datatype score;
    int len;
    struct node *s;

}zzy;

zzy *create();

int empty(zzy *l);

void bian(zzy *l);

int put(zzy *l,datatype score,datatype1 name[20]);

int chazhao(zzy *l,datatype score);

int shang(zzy *l,datatype score);

void paixu(zzy *l);

#endif

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"zzy.h"

zzy *create()
{
    zzy *l=(zzy*)malloc(sizeof(zzy));
    if(NULL==l)
    {
        printf("申请失败");
        return NULL;
    }
        l->s=NULL;
        l->len=0;
        l->score=0;
        printf("申请成功");
        return l;
}

int empty(zzy *l)
{
    if(NULL==l)
    {
        printf("表不合法");
        return -1;
    }
    return l->s==NULL ? 1:0;    
}

void bian(zzy *l)
{
    if(NULL==l || empty(l))
    {
        printf("表空,遍历失败");
        return;
    }
        printf("表中的元素为:");
        zzy *q=l;
        while(q->s != NULL)
        {
            printf("%s%d\t",q->s->name,q->s->score);
            q=q->s;
        }
        printf("\n");
}
int put(zzy *l,datatype score1,datatype1 name1[20])
{
    if(NULL==l)
    {
        printf("链表不合法\n");
        return -3;
    }
        zzy *p=(zzy*)malloc(sizeof(zzy));
        strcpy(p->name,name1);
        p->score=score1;
        zzy *q=l;
        while(q->s != NULL)
        {
            q=q->s;
        }
            q->s=p;
            l->len++;
            printf("添加成功\n");
            return 0;
}
int chazhao(zzy *l,datatype score1)
{
    if(NULL==l)
    {
        printf("链表为空");
        return -4;
    }
    zzy *q=l->s;
    if(q!=NULL)
    {
        if(q->score==score1)
        {
            printf("%s%d",q->name,q->score);
        }
        q=q->s;
    }
}
int shang(zzy *l,datatype score1)
{
    if(NULL==l || empty(l))
    {
        printf("链表为空");
        return -5;
    }
    zzy *q=l;
    while(q->s!=NULL)
    {
        if(q->s->score==score1)
        {
            zzy *p=q->s;
            q->s=p->s;
            free(p);
            p=NULL;
            l->len--;
        }
            q=q->s;
    }

    return 0;
}
void paixu(zzy *l)
{
    if(NULL==l || empty(l))
    {
        printf("链表为空");
        return;
    }
        datatype temp;
        datatype1 name2[20];
        zzy *q=l->s;
        for(int i=1;i<l->len;i++)
        {
            zzy *p=l->s->s;
            for(int a=1;a<i;a++)
            {
                p=p->s;
            }
            for(int k=1;k<=l->len-i;k++)
            {
                if(q->score<p->score)
                {
                    temp=q->score;
                    q->score=p->score;
                    p->score=temp;
                    strcpy(name2,q->name);
                    strcpy(q->name,p->name);
                    strcpy(p->name,name2);
                }
                    p=p->s;
            
            }
                q=q->s;
                free(p);
                p=NULL;
        }
        printf("排序成功");
}
 

更多推荐

章子扬作业

本文发布于:2024-02-27 23:54:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1767063.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:章子   作业

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!