aboutsummaryrefslogtreecommitdiff
path: root/Semestr 4/sieci/pracownia2/router/test.c
blob: ebc6df1e46f61d691d8a7963f34c229a641a93aa (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
#include "linked_list.h"
#include <stdlib.h>
#include <stdio.h>

/* Prints the list of ints to stdio */
void print_list(list_t list) {
  printf("List: ");
  reset(&list);
  while (list.it != NULL) {
    printf("%d, ", *(int *)(list.it->data));
    iterate(&list);
  }
  printf("\n");
  reset(&list);
}

int main() {
  int n;
  scanf("%d", &n);
  list_t list = create_list();

  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    // insert
    if (t == 0) {
      int val = 0;
      scanf("%d", &val);
      insert(&list, &val, sizeof(int));
    }
    if (t == 1) {
      erase(&list);
    }
    if (t == 2) {
      print_list(list);
    }
  }

  free_list(&list);
}