~nloomans/ft_select

ref: 1d90313037b5c7d0545be79e58d8f50a102501ff ft_select/src/list2.c -rw-r--r-- 766 bytes
1d903130Noah Loomans handle CTRL+Z and fg 2 years ago
                                                                                
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
#include <libft.h>
#include "list2.h"

void	list2_insert(
			t_list2_meta *meta,
			t_list2_conn *prev,
			t_list2_conn *new)
{
	new->prev = prev;
	if (new->prev)
	{
		new->next = new->prev->next;
		new->prev->next = new;
		if (new->next != NULL)
			new->next->prev = new;
		else
			meta->last = new;
	}
	else
	{
		new->next = meta->first;
		if (new->next)
			new->next->prev = new;
		meta->first = new;
		if (meta->last == NULL)
			meta->last = new;
	}
	meta->len++;
}

void			list2_unlink(
					t_list2_meta *meta,
					t_list2_conn *conn)
{
	if (meta->first == conn)
		meta->first = conn->next;
	if (meta->last == conn)
		meta->last = conn->prev;
	if (conn->prev)
		conn->prev->next = conn->next;
	if (conn->next)
		conn->next->prev = conn->prev;
	meta->len--;
}