feat: update structure

This commit is contained in:
2024-01-22 14:27:40 +08:00
parent 7836c9185c
commit 3544a28a2e
559 changed files with 120846 additions and 4102 deletions

View File

@@ -0,0 +1,44 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct {
char *name;
int age;
} TPerson;
TPerson *makeNewNode(char *name, int age) {
TPerson *p = (TPerson *) malloc(sizeof(TPerson));
strcpy(p->name, name);
p->age = age;
return p;
}
void freeNode(TPerson *node) {
free(node);
}
#define NUM_PERSONS 3
int main() {
TPerson persons[NUM_PERSONS] = {{"Tan Ah Kow", 65}, {"Sio Bak Pau", 23},
{"Aiken Dueet", 21}};
TPerson *list[NUM_PERSONS];
int i;
printf("ADDING PERSONS\n");
for(i=0; i<NUM_PERSONS; i++) {
printf("Adding %s aged %d\n", persons[i].name, persons[i].age);
list[i] = makeNewNode(persons[i].name, persons[i].age);
}
printf("\nDELETING PERSONS\n");
for(i=0; i<NUM_PERSONS; i++) {
printf("Deleting %s aged %d\n", list[i]->name, list[i]->age);
freeNode(list[i]);
}
}