-
Notifications
You must be signed in to change notification settings - Fork 1
/
print.c
73 lines (68 loc) · 1.8 KB
/
print.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: glasset <glasset@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/18 22:40:55 by glasset #+# #+# */
/* Updated: 2016/11/01 12:10:55 by glasset ### ########.fr */
/* */
/* ************************************************************************** */
#include "nm.h"
void print_list(t_print *cmd)
{
cmd = to_start(cmd);
while (cmd != NULL)
{
if (cmd->type != 'w')
{
ft_putstr(cmd->hexa);
ft_putchar(' ');
ft_putchar(cmd->type);
ft_putchar(' ');
ft_putendl(cmd->name);
}
cmd = cmd->next;
}
}
int is_sort(t_print *cmd)
{
cmd = to_start(cmd);
while (cmd->next != NULL)
{
if (ft_strcmp(cmd->name, cmd->next->name) > 0)
{
return (0);
}
cmd = cmd->next;
}
return (1);
}
void sort(t_print *cmd)
{
t_print *tmp;
tmp = NULL;
while (is_sort(cmd) == 0)
{
cmd = to_start(cmd);
while (cmd->next != NULL)
{
if (ft_strcmp(cmd->name, cmd->next->name) > 0)
{
tmp = cmd;
cmd = cmd->next;
cmd->prev = tmp->prev;
if (tmp->prev != NULL)
tmp->prev->next = cmd;
tmp->prev = cmd;
tmp->next = cmd->next;
if (tmp->next != NULL)
tmp->next->prev = tmp;
cmd->next = tmp;
}
cmd = cmd->next;
}
}
print_list(cmd);
}