Como enlazar nodos de una lista enlazada?
Publicado por Patricio (25 intervenciones) el 16/06/2019 23:23:25
Hola y de ante mano muchas gracias por la ayuda.
Tengo una lista de trabajadores, cada uno con sus datos y cada trabajador puede trabajar horas extras.
Aqui hice un dibujo de como es el esquema para los punteros

Lo que no entiendo es como arreglar el codigo cosa que funcione como en el dibujo en la parte del codigo, como lo puedo modificar para que suceda lo de la imagen?
Tengo una lista de trabajadores, cada uno con sus datos y cada trabajador puede trabajar horas extras.
Aqui hice un dibujo de como es el esquema para los punteros

Lo que no entiendo es como arreglar el codigo cosa que funcione como en el dibujo en la parte del codigo, como lo puedo modificar para que suceda lo de la imagen?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#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;
new = (struct worker *) malloc (sizeof(struct worker));
printf("num_worker: ");
scanf("%d",&new->num_worker); //must verify if worker exist
printf("Name: ");
gets(new->name);
printf("job: ");
gets(new->job);
printf("Base Salary: ");
scanf("%d",&new->base_salary);
new->next = NULL;
if (first==NULL) {
first = new;
last = new;
}
else {
last->next = new;
last = new;
}
}
int Code;
int num_worker;
int day;
int num_exh;
int pay_per_hour;
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) {
printf( "Primer elemento\n");
first_hour = new_h;
last_hour = new_h;
}
else {
last->he_next = new_h;
last_hour = new_h;
}
}
Valora esta pregunta


0