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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
typedef struct s_word
{
char *word;
struct s_word *next;
} t_word;
void aff_list(t_word *word_list)
{
while(word_list)
{
printf("%s\n", word_list->word);
word_list = word_list->next;
}
}
void insert_word(t_word **list, char *line)
{
t_word *new;
t_word *tmp;
t_word *save;
for (tmp = 0, save = *list; *list && strcmp((*list)->word, line) < 0;)
{
tmp = *list;
(*list) = (*list)->next;
}
new = malloc(sizeof(*new));
new->word = strdup(line);
if (!*list)
{
new->next = 0;
if (!save)
save = *list = new;
else
tmp->next = new;
}
else
if (tmp)
{
new->next = tmp->next;
tmp->next = new;
}
else
{
save = new;
new->next = *list;
}
*list = save;
}
typedef struct s_word
{
char *arg;
struct s_list *next;
} t_list;
void my_print_list(t_list *params)
{
t_list *moove;
moove = params;
while (moove != NULL)
{
puts(moove->arg);
moove = moove->next;
}
}
void my_params_in_list(t_list **params, char **av)
{
int y;
t_list *new;
t_list *moove;
y = 0;
while (av[y] != NULL)
{
new = malloc(sizeof(*new));
new->arg = malloc((strlen(av[y]) + 1) * (sizeof(*new->arg)));
new->next = NULL;
strcpy(new->arg, av[y]);
if (*params == NULL)
*params = new;
else
{
moove = *params;
while (moove->next != NULL)
moove = moove->next;
moove->next = new;
}
y++;
}
}
int main(int ac, char **av)
{
t_list *params = NULL;
my_params_in_list(¶ms, av);
my_print_list(params);
return EXIT_SUCCESS;
} |