From 9ff036a93b1ce34ea8a35d8eaeec5e96cb31989e Mon Sep 17 00:00:00 2001 From: Hyder Hadi Date: Sat, 9 May 2026 16:12:20 +0300 Subject: Im redo-ing the Dynamic list to make it better and cleaner --- simple-C-programs/DynamicStudentList.c | 55 +++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/simple-C-programs/DynamicStudentList.c b/simple-C-programs/DynamicStudentList.c index e3e0775..1626f42 100644 --- a/simple-C-programs/DynamicStudentList.c +++ b/simple-C-programs/DynamicStudentList.c @@ -1,11 +1,14 @@ #include #include +#include + struct Student { char *__name; - int __age; int __mark; + int __age; struct Student *__next; + struct Student *__prev; }; struct StudentList { @@ -13,36 +16,52 @@ struct StudentList { struct Student *__tail; int __count; - // Methods; - - int (*highest) (struct StudentList *self); - void (*sort) (struct StudentList *self); + // Methods + struct Student *(*highest) (struct StudentList self); + struct StudentList *(*sort) (struct StudentList self); + void (*put_student) (struct StudentList self, char *name, int age, int mark); + int (*size) (struct StudentList self); + void (*dump) (struct StudentList self); + struct Student *(*find) (struct StudentList self, char *name); + void (*destructor) (struct StudentList self); }; +// Private Functions -int Highest_mark (struct StudentList *self) { - int def = 0; - int res; - struct Student *tmp = NULL; +struct Student *__FIND (struct StudentList *self, char *name) { - if(self->__head != NULL) { - for(tmp = self->__head; self->__count > 0; tmp = tmp->__next) { - if(tmp->__mark > tmp->__next->__mark) { - res = tmp->__mark; - } + struct Student *current = NULL; + + + for(current = self->__head; current != NULL; current = current->__next) { + if(strcmp(name, current->__name) == 0) { + return current; } - return res; } - - return def; + return NULL; } -void Sort_by_mark(struct StudentList *self) { +void __PUT (struct StudentList *self, char *name, int age, int mark) { + struct Student *old, *new; + + old = __FIND(self, name); + + if(old != NULL) { + old->__age = age; + old->__mark = mark; + return; + } + + } + + int main() { + + return 0; } \ No newline at end of file -- cgit v1.2.3