main.c 2.38 KB
Newer Older
William Sha's avatar
William Sha committed
1
2
3
4
5
6
#include <stdio.h>
#include <stdlib.h>
#include "tp3.h"

int main()
{
7
8
    if (DEBUG) printf("Initialization of ChainedLists...\n\n");

9
10
    int action = 0; // represents the choice of the user
    char str_number[5];
Unknown's avatar
   
Unknown committed
11
    char test[5];
12
13
14
15
16

    printf("*****CHAINED LISTS*****\n");
    printf("**UTC - November 2017**\n");
    printf("*****W.Sha - Y.Ly******\n\n");

Unknown's avatar
   
Unknown committed
17
18
19
20
21
22
23
24
25
26
27
    List *lTest = malloc(sizeof(List));
    Element *e1 = malloc(sizeof(Element));
    Element *e2 = malloc(sizeof(Element));
    e1->data = "yaya";
    e1->next = e2;
    e2->data = "Ly";
    e2->next = NULL;
    lTest->head = e1;
    lTest->tail = e2;
    display(lTest);

28
    if (DEBUG) printf("Initialization of an instance of List...\n\n");
Unknown's avatar
Unknown committed
29
    List* default_list;
30
    initialize(&default_list);
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    while(action != 8){
        if (DEBUG) printf("Entering in a new menu prompt...\n\n");

        action = 0;
        // action prompt
        display_menu();
        printf("Your choice : ");
        fflush(stdin);
        scanf("%d", &action);

        while(action == 0 || action < 1 || action > 8){ // not a number or number not in interval
            display_menu();
            printf("Wrong input. Please retry [1-8] : ");
            fflush(stdin); // flushes the buffer
            scanf("%d", &action);
        }

        if (DEBUG) printf("{action = %d}\n", action);
50
        fflush(stdin);
51
52
53

        switch(action){
        case TOKEN_ADD_NB_BEG:
54
55
56
            printf("What do you want to add at the beginning ? ");
            scanf("%s", str_number);
            insert_beginning_list(default_list, str_number);
57
            if (DEBUG) printf("Data inserted case : %s\n", default_list->head->data);
58
59
60
            break;

        case TOKEN_ADD_NB_END:
Unknown's avatar
   
Unknown committed
61
62
63
            printf("What do you want to add at the end ? ");
            scanf("%s", str_number);
            insert_end_list(default_list, str_number);
64
65
66
67
68
69
70
            break;

        case TOKEN_ADD_NB_SPC:
            insert_after_position(NULL, NULL, 0);
            break;

        case TOKEN_DEL_NB_SPC:
71
            remove_element(default_list, 2);
72
73
74
75
76
77
78
            break;

        case TOKEN_SRT_LI_ASC:
            sort(NULL);
            break;

        case TOKEN_DSP_LI_STD:
79
            display(default_list);
80
81
82
            break;

        case TOKEN_RMX_LI_ALL:
83
            destruct(&default_list);
84
85
86
87
88
89
90
            break;

        }

    }

    if (DEBUG) printf("ChainedLists will close...\n");
William Sha's avatar
William Sha committed
91
92
    return 0;
}