| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 445 人关注过本帖
标题:明天就要交作业了,可是还有三个错,求大家帮助!
只看楼主 加入收藏
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
明天就要交作业了,可是还有三个错,求大家帮助!
非师范
搜索更多相关主题的帖子: 作业 
2010-09-29 02:45
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
    long num;
    char name[20];
    float pay;
    long age;
    struct worker *next;
};
/***************创建链表***********************/
struct worker *creat(struct worker *head,int n)
{
    struct worker *p1,*p2;
    int i;
    head=NULL;
    for(i=0;i<n;i++)
    {
        p1=(struct worker*)malloc(LEN);
        printf("num  name  pay  age  \n");
        scanf("%d",&p1->num);
        gets(p1->name);
        scanf("%f",&p1->pay);
        scanf("%d",&p1->age);
        p1->next=NULL;
        if(head==NULL)
            head=p1;
        else
        {
            p2->next=p1;
        }
        p2=p1;
   
    }
    return head;
}
/***************输出链表***********************/
void output(struct worker *head)
{
    struct worker *p;
    p=head;
    printf("num  name  pay  age  \n");
     while(p!=NULL)
     {
         printf("%d,%s,%f,%d \n",p->num,p->name,p->pay,p->age);
         p=p->next;
     }
}
/****************添加节点**********************/
struct worker *insert (struct worker *head)
{
    struct worker *p1,*p2,*p3;
    p1=head;
    p3=(struct worker*)malloc(LEN);
    printf("num  name  pay  age  \n");
        scanf("%d",&p3->num);
        gets(p3->name);
        scanf("%f",&p3->pay);
        scanf("%d",&p3->age);
        p3->next=NULL;
        if(head==NULL)
        {
            head=p3;
            p3->next=NULL;
        }
        else
        {
        
            while((p1->pay)>(p3->pay))
            {p2=p1;
                p1=p1->next;
        }
        if((p1->pay)<(p3->pay))
            if(head==p1)
            {
                head=p3;
                p3->next=p1;
            }
            else
            {
                p2->next=p3;
                p3->next=p1;
             }
            else
            {
                if (p1->next=NULL)
                {p1->next=p3;
                p3->next=NULL;
                }
            }
        }
/****************删除节点**********************/
struct worker *delet(struct worker *head)
{
    struct worker *p1,*p2;
int n;
p1=P蘆
2010-09-29 02:45
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
    long num;
    char name[20];
    float pay;
    long age;
    struct worker *next;
};
/***************创建链表***********************/
struct worker *creat(struct worker *head,int n)
{
    struct worker *p1,*p2;
    int i;
    head=NULL;
    for(i=0;i<n;i++)
    {
        p1=(struct worker*)malloc(LEN);
        printf("num  name  pay  age  \n");
        scanf("%d",&p1->num);
        gets(p1->name);
        scanf("%f",&p1->pay);
        scanf("%d",&p1->age);
        p1->next=NULL;
        if(head==NULL)
            head=p1;
        else
        {
            p2->next=p1;
        }
        p2=p1;
   
    }
    return head;
}
/***************输出链表***********************/
void output(struct worker *head)
{
    struct worker *p;
    p=head;
    printf("num  name  pay  age  \n");
     while(p!=NULL)
     {
         printf("%d,%s,%f,%d \n",p->num,p->name,p->pay,p->age);
         p=p->next;
     }
}
/****************添加节点**********************/
struct worker *insert (struct worker *head)
{
    struct worker *p1,*p2,*p3;
    p1=head;
    p3=(struct worker*)malloc(LEN);
    printf("num  name  pay  age  \n");
        scanf("%d",&p3->num);
        gets(p3->name);
        scanf("%f",&p3->pay);
        scanf("%d",&p3->age);
        p3->next=NULL;
        if(head==NULL)
        {
            head=p3;
            p3->next=NULL;
        }
        else
        {
        
            while((p1->pay)>(p3->pay))
            {p2=p1;
                p1=p1->next;
        }
        if((p1->pay)<(p3->pay))
            if(head==p1)
            {
                head=p3;
                p3->next=p1;
            }
            else
            {
                p2->next=p3;
                p3->next=p1;
             }
            else
            {
                if (p1->next=NULL)
                {p1->next=p3;
                p3->next=NULL;
                }
            }
        }
/****************删除节点**********************/
struct worker *delet(struct worker *head)
{
    struct worker *p1,*p2;
int n;
p1=P蘆
2010-09-29 02:45
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
    long num;
    char name[20];
    float pay;
    long age;
    struct worker *next;
};
/***************创建链表***********************/
struct worker *creat(struct worker *head,int n)
{
    struct worker *p1,*p2;
    int i;
    head=NULL;
    for(i=0;i<n;i++)
    {
        p1=(struct worker*)malloc(LEN);
        printf("num  name  pay  age  \n");
        scanf("%d",&p1->num);
        gets(p1->name);
        scanf("%f",&p1->pay);
        scanf("%d",&p1->age);
        p1->next=NULL;
        if(head==NULL)
            head=p1;
        else
        {
            p2->next=p1;
        }
        p2=p1;
   
    }
    return head;
}
/***************输出链表***********************/
void output(struct worker *head)
{
    struct worker *p;
    p=head;
    printf("num  name  pay  age  \n");
     while(p!=NULL)
     {
         printf("%d,%s,%f,%d \n",p->num,p->name,p->pay,p->age);
         p=p->next;
     }
}
/****************添加节点**********************/
struct worker *insert (struct worker *head)
{
    struct worker *p1,*p2,*p3;
    p1=head;
    p3=(struct worker*)malloc(LEN);
    printf("num  name  pay  age  \n");
        scanf("%d",&p3->num);
        gets(p3->name);
        scanf("%f",&p3->pay);
        scanf("%d",&p3->age);
        p3->next=NULL;
        if(head==NULL)
        {
            head=p3;
            p3->next=NULL;
        }
        else
        {
        
            while((p1->pay)>(p3->pay))
            {p2=p1;
                p1=p1->next;
        }
        if((p1->pay)<(p3->pay))
            if(head==p1)
            {
                head=p3;
                p3->next=p1;
            }
            else
            {
                p2->next=p3;
                p3->next=p1;
             }
            else
            {
                if (p1->next=NULL)
                {p1->next=p3;
                p3->next=NULL;
                }
            }
        }
/****************删除节点**********************/
struct worker *delet(struct worker *head)
{
    struct worker *p1,*p2;
inP蘆
2010-09-29 02:46
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
    long num;
    char name[20];
    float pay;
    long age;
    struct worker *next;
};
/***************创建链表***********************/
struct worker *creat(struct worker *head,int n)
{
    struct worker *p1,*p2;
    int i;
    head=NULL;
    for(i=0;i<n;i++)
    {
        p1=(struct worker*)malloc(LEN);
        printf("num  name  pay  age  \n");
        scanf("%d",&p1->num);
        gets(p1->name);
        scanf("%f",&p1->pay);
        scanf("%d",&p1->age);
        p1->next=NULL;
        if(head==NULL)
            head=p1;
        else
        {
            p2->next=p1;
        }
        p2=p1;
   
    }
    return head;
}
/***************输出链表***********************/
void output(struct worker *head)
{
    struct worker *p;
    p=head;
    printf("num  name  pay  age  \n");
     while(p!=NULL)
     {
         printf("%d,%s,%f,%d \n",p->num,p->name,p->pay,p->age);
         p=p->next;
     }
}
/****************添加节点**********************/
struct worker *insert (struct worker *head)
{
    struct worker *p1,*p2,*p3;
    p1=head;
    p3=(struct worker*)malloc(LEN);
    printf("num  name  pay  age  \n");
        scanf("%d",&p3->num);
        gets(p3->name);
        scanf("%f",&p3->pay);
        scanf("%d",&p3->age);
        p3->next=NULL;
        if(head==NULL)
        {
            head=p3;
            p3->next=NULL;
        }
        else
        {
        
            while((p1->pay)>(p3->pay))
            {p2=p1;
                p1=p1->next;
        }
        if((p1->pay)<(p3->pay))
            if(head==p1)
            {
                head=p3;
                p3->next=p1;
            }
            else
            {
                p2->next=p3;
                p3->next=p1;
             }
            else
            {
                if (p1->next=NULL)
                {p1->next=p3;
                p3->next=NULL;
                }
            }
        }
/****************删除节点**********************/
struct worker *delet(struct worker *head)
{
    struct worker *p1,*p2;
int n;P蘆
2010-09-29 02:46
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
收藏
得分:0 
作业.zip (1.45 KB)
2010-09-29 02:48
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
收藏
得分:20 
程序代码:
       #include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct worker)
struct worker
{
    long num;
    char name[20];
    float pay;
    long age;
    struct worker *next;
};
/***************创建链表***********************/
struct worker *creat(struct worker *head,int n)
{
    struct worker *p1,*p2;
    int i;
    head=NULL;
    for(i=0;i<n;i++)
    {
        p1=p2=(struct worker*)malloc(LEN);
        printf("num  name  pay  age  \n");
        scanf("%d",&p1->num);
        gets(p1->name);
        scanf("%f",&p1->pay);
        scanf("%d",&p1->age);
        p1->next=NULL;
        if(head==NULL)
            head=p1;
        else
        {
            p2->next=p1;
        }
        p2=p1;
   
    }
    return head;
}
/***************输出链表***********************/
void output(struct worker *head)
{
    struct worker *p;
    p=head;
    printf("num  name  pay  age  \n");
     while(p!=NULL)
     {
         printf("%d,%s,%f,%d \n",p->num,p->name,p->pay,p->age);
         p=p->next;
     }
}
/****************添加节点**********************/
struct worker *insert (struct worker *head)
{
    struct worker *p1,*p2,*p3;
    p1=head;
    p3=(struct worker*)malloc(LEN);
    printf("num  name  pay  age  \n");
        scanf("%d",&p3->num);
        gets(p3->name);
        scanf("%f",&p3->pay);
        scanf("%d",&p3->age);
        p3->next=NULL;
        if(head==NULL)
        {
            head=p3;
            p3->next=NULL;
        }
        else
        {
       
            while((p1->pay)>(p3->pay))
            {p2=p1;
                p1=p1->next;
        }
        if((p1->pay)<(p3->pay))
            if(head==p1)
            {
                head=p3;
                p3->next=p1;
            }
            else
            {
                p2->next=p3;
                p3->next=p1;
             }
            else
            {
                if (p1->next==NULL)
                {p1->next=p3;
                p3->next=NULL;
                }
            }
        }
/****************删除节点**********************/
struct worker *delet(struct worker * head )
{
    struct worker *p1,*p2;
int n;
p1=head;
if(head==NULL)
printf("\n 链表为空\n");
else
{printf("\n 请输入要删除的职工号\n");
scanf("%d",&n);
while (strcmp(p1->num,n)!=0 && p1->next!=NULL)
{
    p2=p1;
    p1=p1->next;

}
if(strcmp(p1->num,n)==0 )
{
    if(p1==head)
    {
        head=head->next;
        free(p1);break;
    }
    else
    {
        p2->next=p1->next;
        free(p1);break;
    }
}
else printf("\n没有找到要删除的对象\n");
}
return(head);
}

/****************主函数*********************/
void main()
{
    int n,m,t;
struct worker *head;
head=NULL;
printf("输入要创建的节点数\n");
scanf("%d",&n);
a=creat(head,n);
output(head);
loop: while(t)
      {
          printf("1,添加节点\n");
          printf("2,删除节点\n");
          printf("3,查看链表\n");
scanf("%d",&m);
switch(m)
{
case 1:a=insert(head);goto loop;
case 2:a=delet(head);goto loop;
case 3:output(head);goto loop;
default:printf("输入错误");
}
      }
   
}

}
我给你改了下,只有一个错误了,我现在也没时间了,我要上课了!!你自己再看看吧!!期待你把改过后的代码发上来!!

付出终将有回报!Ibelieve!
2010-09-29 09:40
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
收藏
得分:0 
while (strcmp(p1->num,n)!=0 && p1->next!=NULL)
你这个比较工号是比较数字,我觉得应该不要用strcmp函数吧!!

付出终将有回报!Ibelieve!
2010-09-29 09:44
快速回复:明天就要交作业了,可是还有三个错,求大家帮助!
数据加载中...
 
   



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

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