aboutsummaryrefslogtreecommitdiff
path: root/simple-C-programs/DynamicStudentList.c
blob: 1626f42c368eaefde1e96ec4ac1104409cdd8463 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct Student {
  char *__name;
  int __mark;
  int __age;
  struct Student *__next;
  struct Student *__prev;
};

struct StudentList {
  struct Student *__head;
  struct Student *__tail;
  int __count;

  // 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

struct Student *__FIND (struct StudentList *self, char *name) {

  struct Student *current = NULL;


  for(current = self->__head; current != NULL; current = current->__next) {
    if(strcmp(name, current->__name) == 0) {
      return current;
    }
  }
  return NULL;
}

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;
}