-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkcut.c
54 lines (49 loc) · 1.54 KB
/
linkcut.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* linkcut.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cgleason <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/11 14:30:50 by cgleason #+# #+# */
/* Updated: 2018/09/11 14:31:46 by cgleason ### ########.fr */
/* */
/* ************************************************************************** */
#include "ants.h"
void access(t_splay *node)
{
splay(node);
while (node->pathparent)
{
splay(node->pathparent);
node->parent = node->pathparent;
node->pathparent->right->pathparent = node->pathparent;
node->pathparent->right->parent = NULL;
node->pathparent->right = node;
splay(node);
}
}
t_splay *find_root(t_splay *node)
{
access(node);
while (node->left)
node = node->left;
return (node);
}
void cut(t_splay *node)
{
access(node);
if (node->left)
{
node->left->parent = NULL;
node->left->pathparent = node;
}
node->left = NULL;
}
void link(t_splay *root, t_splay *node)
{
access(root);
access(node);
root->left = node;
node->parent = root;
}