如何将另一个链接列表链接到当前列表的每个节点?

时间:2019-06-16 21:10:51

标签: c database linked-list

我正在尝试创建一个工人列表,其中每个工人每个月的每一天都可以有更多的工作时间应用到他的工作中,并且为了简化起见,天数仅是1到30,因此无需使用日期。 事实是,每个增加的工人每天都可以申请加班。 我遇到的问题是如何关联指针和链接列表以使其正常工作。我已经完成了绘图,并试图将其应用于代码,但是我对如何执行此操作感到困惑。

enter image description here

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>

struct worker {
    int num_worker;
    char name[20];
    char job[12];
    int base_salary;
    struct worker *next, *he_next;
};

struct extras_hours{
    int code;
    int num_worker;
    int day;
    int num_exh;
    int pay_per_hour;
    struct extras_hours *he_next
};

struct worker *first, *last;
struct extra_hours *first_hour, *last_hour

void add_new_worker() {
    struct worker *new_w;

    new_w = (struct worker *) malloc (sizeof(struct worker));
    printf("num_worker: ");
    scanf("%d",&new->num_worker); //must verify  if worker exist
    printf("Name: ");
    gets(new_w->name);
    printf("job: ");
    gets(new_w->job);
    printf("Base Salary: ");
    scanf("%d",&new_w->base_salary);

    new_w->next = NULL;

    if (first==NULL) {
        first = new_w;
        last = new_w;
    }
    else {
        last->next = new_w;
        last = new_w;
    }
}

void add_extra_hours(){
    struct extra_hours *new_h;

    new_h = (struct extras_hours *) malloc (sizeof(struct extras_hours));

    printf("New Extra Hours");
    printf("\n new extra hours for worker number:\n");
    printf("num_worker: ");
    scanf("%d",&new_h->num_worker); //must verify that worker exist
    printf("Code: ");
    scanf("%d",&new_h->code);
    printf("day: "); //must verify is worker already worked extra this day
    scanf("%d",&new_h->day);  // must be number between 1 and 30
    printf("Number of extra hours: ");
    scanf("%d",&new_h->num_exh);
    printf("Extra Payment per hour: ");
    // (base_salary/180)*1.5, its the base salary of worker. each worker can have different base salary
    scanf("%d",&new_h->pay_per_hour);

    new_h->he_next = NULL;

    if (first_hour==NULL) {
        first_hour = new_h;
        last_hour = new_h;
    }
    else {
        last_hour->he_next = new_h;
        last_hour = new_h;
    }
}

对保留新内容进行了一些修复。现在是new_h

0 个答案:

没有答案