| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 246 人关注过本帖
标题:一个链表(问)题的修改,学生信息表
只看楼主 加入收藏
a951122
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-12-22
结帖率:0
收藏
 问题点数:0 回复次数:1 
一个链表(问)题的修改,学生信息表
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{
    char num[20];
    char name[20];
    float score[5];
    struct student*next;
};
struct student*head=NULL;
void insert(struct student*);
;
void insert ();
void print ();
void creat ();
void query ();


void main()
{
    creat ();
    print ();
    query ();

}

void insert(struct student*newp)
{
    struct student*p=head,*q=head;
    if(head==NULL)
    {
        head=newp;
    newp->next=NULL;
    }
else
{
    while(strcmp(p->num,newp->num)<0&&p->next!=NULL)
    {
        q=p;
        p=p->next;
    }
    if(strcmp(p->num,newp->num)>0)
    {
        newp->next=p;
        if(p==head)
            head=newp;
        else
            q->next=newp;

    }
    else if(strcmp(p->num,newp->num)==0)
        printf("input invalid!\n");
    else
    {
        p->next=newp;
        newp->next=NULL;
    }
}
}
void creat ()
{
    struct student*newp;
    newp=(struct student*)malloc(sizeof(struct student));
    printf("information(NO NAME SCORE):\n");
    scanf("%s%s%f", &newp->num, &newp->name, &newp->score);
    while(strcmp(newp->num,"#")!=0)
    {
        insert(newp);
        newp=(struct student*)malloc(sizeof(struct student));
        scanf("%s%s%f", &newp->num, &newp->name, &newp->score);
    }
}

void print ()
{   int average=0;
    struct student*p=head;
    while(p!=NULL)
    {
       printf("s%s%f%\n",p->num,p->name,p->score);
       p=p->next;
    }
    while(p!=NULL)
    {
        average=average+p->score;
        p=p->next;
    }
}

void query ()
{
    struct student*p;
    char sname[20],snum[20],value[20];
    int find;
    do
    {
        p=head;
        find=0;
        printf("please input del condition:\n");
        printf("name search(sno,sname,sco):");
        scanf("%s",sname);
        printf("value");
        scanf("%s",value);
        if(strcmp(sname,"sno")==0)
        while(p!=NULL)
        {
            if(strcmp(p->num,value)==0)
            {
                printf("%s%s%f\n",p->num,p->name,p->score);
                find=1;
                break;
            }
            p=p->next;
        }
        else if (strcmp(sname,"sco")==0)
        {
            while(p!=NULL)
            {
               if(strcmp(p->score,value)==0)
               {
                printf("%s%s%f\n",p->num,p->name,p->score);
                find=1;
               }
               else
                   printf("not exist!\n");

               if(!find)
                   printf("cannot find");
            }
        }
    }
}
然后还有删除其中一个节点的操作不会编,求大神帮忙改一下
搜索更多相关主题的帖子: insert include 
2013-12-22 11:37
a951122
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-12-22
收藏
得分:0 
求大神解答
2013-12-22 11:48
快速回复:一个链表(问)题的修改,学生信息表
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040047 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved