工号自动生成c语言,建立一个链表,每个结点包含:取工号,工资和指针,要求编程完成以下:...

得分:10

ca56232b3bbedf9a539d07f37fffb99a.gif

3144d8b7615c79d9f638db40d5689d26.gif

a218af6549b45ee526caf607ebff1358.gif

0f8df0e29816ae721419de940fb833d1.gif

#include

#include

#include

#define  LENGTH  12

#define  OK  1

#define  ERROR  0

#define  Null  0

struct Node     /*定义职工信息的结点*/

{

char jobnum[LENGTH];

long  wages;

struct Node *next;

};

typedef struct Node staff;

typedef struct Node *StInfor;

int InitLinklist(StInfor List,int num)     /*初始化链表,默认所有信息为空*/

{

StInfor peop,p=List;     /*peop:指向新结点的指针。p:指向当前结点的指针。*/

while(num--)

{

peop=(staff *)malloc(sizeof(staff));

p->next=peop;

p=peop;

}

p->next=Null;

printf("\nThe InitLinklist operation is OK.\n");

}

int InputInfor(StInfor List,int num)      /*向链表中输入信息*/

{

StInfor p=List->next;    /*p:指向当前结点的指针。*/

int i=1;

printf("\nThe number of the staff is %d.\n",num);

while(num--)

{

printf("\nPlease enter the %d staff's information:",i);

printf("\nEnter the staff's jobnumber:");

fflush(stdin);

scanf("%s",p->jobnum);

printf("\nEnter the staff's wages:");

scanf("%ld",&p->wages);

p=p->next;

i++;

}

printf("\nThe InputInfor operation is OK.\n");

}

int printfLinklist(StInfor List)     /*输出链表*/

{

StInfor p=List->next;

printf("\nThe information of the list are:\n");

printf("\n staff's number \tstaff's wages");

while(p)

{

printf("\n %-14s \t%12ld",p->jobnum,p->wages);

p=p->next;

}

}

int InsertLinklist(StInfor List)      /*向链表中插入结点*/

{

StInfor peop,q=List,p=q->next;

/*peop:指向待插入的新结点的指针。q:指向新节点的前驱结点的指针。p:指向新节点的后继结点的指针。*/

printf("\nPlease enter the staff's information which you want to insert.");

peop=(staff *)malloc(sizeof(staff));

printf("\nEnter the staff's jobnumber:");

fflush(stdin);

scanf("%s",peop->jobnum);

printf("\nEnter the staff's wages:");

scanf("%ld",&peop->wages);

while(strcmp(p->jobnum,peop->jobnum)!=1)

{

q=p;

p=p->next;

if(!p)

{

peop->next=q->next;

q->next=peop;

return OK;

}

}

peop->next=q->next;

q->next=peop;

printf("\nThe InsertLinklist operation is OK.\n");

}

int deleteLinklist(StInfor List)     /*删除链表中相应的职工信息*/

{

char jobnum[LENGTH];    /*jobnum:待删职工的工号。*/

StInfor q=List,p=q->next;    /*q:指向待删职工结点的前驱结点的指针。p:指向待删职工结点的指针。*/

printf("\nPlease enter the staff's information which you want to delete.");

fflush(stdin);

scanf("%s",jobnum);

while(strcmp(p->jobnum,jobnum))

{

q=p;

p=p->next;

if(!p)

{

printf("\nDoesn't find the staff.\n");

return ERROR;

}

}

q->next=p->next;

free(p);

printf("\nThe InsertLinklist operation is OK.\n");

}

int main()

{

StInfor List;    /*List:定义链表*/

int num;      /*num:链表中的职工数目*/

char conti;     /*conti:是否继续进行操作*/

printf("\nplease enter the total number of the staff:");

scanf("%d",&num);

InitLinklist(List,num);    /*初始化链表*/

InputInfor(List,num);     /*向链表输入信息*/

do{

printfLinklist(List);    /*输出链表*/

InsertLinklist(List);    /*插入职工*/

deleteLinklist(List);    /*删除职工*/

printf("\nContinue,enter 'Y/y';or enter others.\n");    /*确定是否继续进行操作*/

fflush(stdin);

conti=getchar();

}while(conti=='Y'||conti=='y');

}

希望对你能有帮助

13a2f4bd84d8af35e7645442bb7a26a3.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值