-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC.c
More file actions
248 lines (248 loc) · 5.32 KB
/
ABC.c
File metadata and controls
248 lines (248 loc) · 5.32 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//#define _CRT_SECURE_NO_WARNINGS
//
//#include<stdio.h>
//#include<malloc.h>
//#include<string.h>
//
//#define NUME_FISIER "Proiecte.txt"
//
//
//struct Proiect {
// unsigned int codP;
// char* titlu;
// char* beneficiar;
// int nrEx;
// char** executanti;
// float buget;
//};
//
//typedef struct Proiect Proiect;
//
//struct NodArbore {
// struct Proiect info;
// struct NodArbore* st, *dr;
//};
//
//typedef struct NodArbore NodArbore;
//
//NodArbore* inserare_ABC(NodArbore* r, Proiect p, unsigned char* flag)
//{
// if (r != NULL)
// {
// if (r->info.codP < p.codP)
// {
// r->st = inserare_ABC(r->st, p, flag);
// }
// else
// {
// if (r->info.codP > p.codP)
// {
// r->dr = inserare_ABC(r->dr, p, flag);
// }
// else
// {
// *flag = 0;
// }
// }
// }
// else
// {
// r = malloc(sizeof(NodArbore));
// r->info = p;
// r->st = NULL;
// r->dr = NULL;
// *flag = 1;
// }
// return r;
//}
//
//void traversare_inordine(NodArbore* r)
//{
// if (r != NULL)
// {
// traversare_inordine(r->st);
// printf("Nodul cu cheie %u al proiectului %s.\n",r->info.codP,r->info.beneficiar);
// traversare_inordine(r->dr);
// }
//}
//
//void traversare_inordine_EXEC(NodArbore* r,unsigned int cheie)
//{
// if (r != NULL)
// {
// traversare_inordine_EXEC(r->st,cheie);
// if (r->info.codP == cheie)
// {
// printf("Nr executanti : %d \n", r->info.nrEx);
// for (unsigned char i = 0;i < r->info.nrEx;i++)
// {
// printf("Executant %d -> %s \n", r->info.nrEx, r->info.executanti[i]);
// }
// }
// traversare_inordine_EXEC(r->dr,cheie);
// }
//}
//
//struct Nod {
// Proiect info;
// struct Nod* next;
//};
//typedef struct Nod Nod;
//
//Nod* inserare_sf(Nod* lista, Proiect p)
//{
// Nod* nou = malloc(sizeof(Nod));
// nou->info = p;
// nou->next = NULL;
// if (lista == NULL)
// {
// lista = nou;
// }
// else
// {
// Nod* temp = lista;
// while (temp->next != NULL)
// {
// temp = temp->next;
// }
// temp->next = nou;
// }
// return lista;
//}
//
//void cautare_ABC(NodArbore* r,float buget,Nod** lista)
//{
// if (r != NULL)
// {
// if (r->info.buget > buget)
// {
// *lista = inserare_sf(*lista, r->info);
// }
// cautare_ABC(r->st, buget, lista);
// cautare_ABC(r->dr, buget, lista);
// }
//}
//
//void traversare_ls(Nod* lista)
//{
// if (lista != NULL)
// {
// printf("Proiect %u pentru %s a fost salvat cu buget %f.\n",
// lista->info.codP,lista->info.beneficiar,lista->info.buget);
// traversare_ls(lista->next);
// }
//}
//
//NodArbore* modificare_list_exec(NodArbore* r,unsigned int cheie, unsigned int nrEx, char** noiExec)
//{
// if (r != NULL)
// {
// if (r->info.codP == cheie)
// {
// for (unsigned char i = 0;i < r->info.nrEx;i++)
// {
// free(r->info.executanti[i]);
// }
// free(r->info.executanti);
// r->info.nrEx = nrEx;
// r->info.executanti = malloc(nrEx*sizeof(char*));
// for (unsigned char i = 0;i < nrEx;i++)
// {
// r->info.executanti[i] = malloc(strlen(noiExec[i]) + 1);
// strcpy(r->info.executanti[i], noiExec[i]);
// }
// }
// r->st = modificare_list_exec(r->st, cheie, nrEx, noiExec);
// r->dr = modificare_list_exec(r->dr, cheie, nrEx, noiExec);
// }
// return r;
//}
//
//int main()
//{
// Proiect p;
// NodArbore* root = NULL;
// FILE* f = NULL;
// char buffer[256];
// f = fopen(NUME_FISIER, "r");
// unsigned char flag = 0;
// fgets(buffer, sizeof(buffer), f);
// while (!feof(f))
// {
// strtok(buffer, "\n");
// sscanf(buffer, "%u", &p.codP);
//
// fgets(buffer, sizeof(buffer), f);
// strtok(buffer, "\n");
// p.titlu = malloc(strlen(buffer) + 1);
// strcpy(p.titlu, buffer);
//
// fgets(buffer, sizeof(buffer), f);
// strtok(buffer, "\n");
// p.beneficiar = malloc(strlen(buffer) + 1);
// strcpy(p.beneficiar, buffer);
//
// fgets(buffer, sizeof(buffer), f);
// strtok(buffer, "\n");
// p.nrEx = (int)atoi(buffer);
//
// p.executanti = malloc(p.nrEx * sizeof(char*));
// for (unsigned char i = 0;i < p.nrEx;i++)
// {
// fgets(buffer, sizeof(buffer), f);
// strtok(buffer, "\n");
// p.executanti[i] = malloc(strlen(buffer) + 1);
// strcpy(p.executanti[i], buffer);
// }
// fgets(buffer, sizeof(buffer), f);
// strtok(buffer, "\n");
// sscanf(buffer, "%f", &p.buget);
// root = inserare_ABC(root, p, &flag);
// if (flag == 1)
// {
// printf("Proiectul %u -> %s, inserat cu succes, %.2f.\n", p.codP, p.titlu,p.buget);
// }
// else
// {
// printf("Inserare esuata!\n");
// free(p.titlu);
// free(p.beneficiar);
// for (int i = 0; i < p.nrEx; i++) {
// free(p.executanti[i]);
// }
// free(p.executanti);
// }
// fgets(buffer, sizeof(buffer), f);
// }
// fclose(f);
//
// printf("Traversare INORDINE a arborelui:\n");
// traversare_inordine(root);
//
// Nod* prim = NULL;
// cautare_ABC(root, 35000.00, &prim);
// printf("Nodurile cu buget mai mare de 35000:\n");
// traversare_ls(prim);
//
// Nod* t = NULL;
// while (prim != NULL)
// {
// t = prim;
// prim = prim->next;
// free(t);
// }
// printf("Lista : \n");
// traversare_ls(prim);
//
// traversare_inordine_EXEC(root, 102);
// char** nume = malloc(sizeof(char*) * 2);
// nume[0] = malloc(strlen("Mihai Mihaita") + 1);
// strcpy(nume[0], "Mihai Mihaita");
// nume[1] = malloc(strlen("Mihai Oana") + 1);
// strcpy(nume[1], "Mihai Oana");
// root = modificare_list_exec(root, 102, 2, nume);
// traversare_inordine_EXEC(root, 102);
// free(nume[0]); free(nume[1]);
// free(nume);
// return 0;
//}