| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 318 人关注过本帖
标题:明天就要交作业了,可是还有三个错,求大家
只看楼主 加入收藏
xyq129052
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-9-29
结帖率:0
收藏
 问题点数:0 回复次数: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=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-&gP蘆
搜索更多相关主题的帖子: 作业 
2010-09-29 02:43
快速回复:明天就要交作业了,可是还有三个错,求大家
数据加载中...
 
   



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

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