-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlist_ins_sort.c
44 lines (38 loc) · 960 Bytes
/
dlist_ins_sort.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
/*
** dlist_ins_sort.c for dlist in /Users/mataejoon/programming/lib/dlist
**
** Made by Mathieu TAN
** Login <[email protected]>
**
** Started on Thu Dec 20 20:39:44 2012 Mathieu TAN
** Last update Fri Dec 21 01:41:10 2012 Mathieu TAN
*/
#include <stdio.h>
#include "dlist.h"
#include "fake.h"
int cmp_node(t_dlist *list, t_data *new, t_dlist_elem *elem)
{
int res;
t_data *d2;
d2 = elem->data;
res = list->cmp(new->name, d2->name);
printf("s1=%s, s2=%s : %d\n", new->name, d2->name, res);
return (res);
}
int dlist_ins_sort(t_dlist *list, const void *data)
{
t_dlist_elem *elem;
elem = list->head;
while (elem)
{
if (cmp_node(list, (t_data *)data, elem) >= 0)
elem = elem->next;
else
{
printf("prev: data[%s]\n", ((t_data*)data)->name);
return (dlist_ins_prev(list, elem, data));
}
}
printf("next: data[%s]\n", ((t_data*)data)->name);
return (dlist_ins_next(list, list->tail, data));
}