norm stuff and delif now dels pointer to lst also......
This commit is contained in:
parent
aca4a52f15
commit
8960d54455
8 changed files with 81 additions and 48 deletions
|
|
@ -6,54 +6,73 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
|
/* Created: 2016/11/14 18:06:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/16 11:24:32 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 15:13:44 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "btree.h"
|
#include "btree.h"
|
||||||
int _print_t(t_btree *tree, int is_left, int offset, int depth, char s[20][255], char *(*printer)(void *))
|
|
||||||
|
enum e_data
|
||||||
|
{
|
||||||
|
is_left,
|
||||||
|
offset,
|
||||||
|
depth,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int print_t(t_btree *tree,
|
||||||
|
int data[3], char s[20][255], char *(*printer)(void *))
|
||||||
{
|
{
|
||||||
char b[20];
|
char b[20];
|
||||||
int width = 5;
|
int width;
|
||||||
|
int left;
|
||||||
|
int right;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
width = 5;
|
||||||
if (!tree)
|
if (!tree)
|
||||||
return 0;
|
return (0);
|
||||||
/* ft_printf("new tree elem: %s\n", printer(tree)); */
|
|
||||||
sprintf(b, "%5s", printer(tree->item));
|
sprintf(b, "%5s", printer(tree->item));
|
||||||
int left = _print_t(tree->left, 1, offset, depth + 1, s, printer);
|
left = print_t(tree->left, (int[3]){
|
||||||
int right = _print_t(tree->right, 0, offset + left + width, depth + 1, s, printer);
|
1, data[offset], data[depth] + 1}, s, printer);
|
||||||
#ifdef COMPACT
|
right = print_t(tree->right, (int[3]){
|
||||||
for (int i = 0; i < width; i++)
|
0, data[offset] + left + width, data[depth] + 1}, s, printer);
|
||||||
s[depth][offset + left + i] = b[i];
|
i = -1;
|
||||||
if (depth && is_left)
|
while (++i < width)
|
||||||
|
s[data[depth]][data[offset] + left + i] = b[i];
|
||||||
|
if (data[depth] && data[is_left])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < width + right; i++)
|
i = -1;
|
||||||
s[depth - 1][offset + left + width/2 + i] = '-';
|
while (++i < width)
|
||||||
s[depth - 1][offset + left + width/2] = '.';
|
s[data[depth] - 1][data[offset] + left + width / 2 + i] = '-';
|
||||||
|
s[data[depth] - 1][data[offset] + left + width / 2] = '.';
|
||||||
}
|
}
|
||||||
else if (depth && !is_left)
|
else if (data[depth] && !data[is_left])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < left + width; i++)
|
i = -1;
|
||||||
s[depth - 1][offset - width/2 + i] = '-';
|
while (++i < width)
|
||||||
s[depth - 1][offset + left + width/2] = '.';
|
s[data[depth] - 1][data[offset] - width / 2 + i] = '-';
|
||||||
|
s[data[depth] - 1][data[offset] + left + width / 2] = '.';
|
||||||
}
|
}
|
||||||
#else
|
i = -1;
|
||||||
for (int i = 0; i < width; i++)
|
while (++i < width)
|
||||||
s[2 * depth][offset + left + i] = b[i];
|
s[2 * data[depth]][data[offset] + left + i] = b[i];
|
||||||
if (depth && is_left)
|
if (data[depth] && data[is_left])
|
||||||
{
|
{
|
||||||
for (int i = 0; i < width + right; i++)
|
i = -1;
|
||||||
s[2 * depth - 1][offset + left + width/2 + i] = '-';
|
while (++i < width)
|
||||||
s[2 * depth - 1][offset + left + width/2] = '+';
|
s[2 * data[depth] - 1][data[offset] + left + width / 2 + i] = '-';
|
||||||
s[2 * depth - 1][offset + left + width + right + width/2] = '+';
|
s[2 * data[depth] - 1][data[offset] + left + width / 2] = '+';
|
||||||
|
s[2 * data[depth] - 1][
|
||||||
|
data[offset] + left + right + 3 * width / 2] = '+';
|
||||||
}
|
}
|
||||||
else if (depth && !is_left) {
|
else if (data[depth] && !data[is_left])
|
||||||
for (int i = 0; i < left + width; i++)
|
{
|
||||||
s[2 * depth - 1][offset - width/2 + i] = '-';
|
i = -1;
|
||||||
s[2 * depth - 1][offset + left + width/2] = '+';
|
while (++i < width)
|
||||||
s[2 * depth - 1][offset - width/2 - 1] = '+';
|
s[2 * data[depth] - 1][data[offset] - width / 2 + i] = '-';
|
||||||
|
s[2 * data[depth] - 1][data[offset] + left + width / 2] = '+';
|
||||||
|
s[2 * data[depth] - 1][data[offset] - width / 2 - 1] = '+';
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return (left + width + right);
|
return (left + width + right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,13 +80,15 @@ void btree_print(t_btree *tree, char *(*printer)(void *))
|
||||||
{
|
{
|
||||||
char s[20][255];
|
char s[20][255];
|
||||||
char empty[255];
|
char empty[255];
|
||||||
/* for (int i = 0; i < 20; i++) */
|
int i;
|
||||||
/* s[i][1] = 0; */
|
|
||||||
for (int i = 0; i < 20; i++)
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
sprintf(s[i], "%80s", " ");
|
sprintf(s[i], "%80s", " ");
|
||||||
sprintf(empty, "%80s", " ");
|
sprintf(empty, "%80s", " ");
|
||||||
_print_t(tree, 0, 0, 0, s, printer);
|
print_t(tree, (int[3]){0, 0, 0}, s, printer);
|
||||||
for (int i = 0; i < 20; i++)
|
i = -1;
|
||||||
|
while (++i < 20)
|
||||||
{
|
{
|
||||||
if (ft_strcmp(s[i], empty) == 0)
|
if (ft_strcmp(s[i], empty) == 0)
|
||||||
break ;
|
break ;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/16 18:30:10 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 15:15:04 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/16 18:23:24 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 14:22:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ void ft_lst_delif(
|
||||||
{
|
{
|
||||||
tmp = (*indirect);
|
tmp = (*indirect);
|
||||||
(*indirect) = (*indirect)->next;
|
(*indirect) = (*indirect)->next;
|
||||||
(*del)(tmp->content, tmp->content_size);
|
ft_lstdelone(&tmp, del);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
indirect = &(*indirect)->next;
|
indirect = &(*indirect)->next;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
|
/* Created: 2016/11/04 11:09:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/04 11:11:30 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 12:36:08 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
|
/* Created: 2016/11/03 15:18:57 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/16 18:24:38 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 14:02:16 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
|
/* Created: 2016/11/03 14:57:15 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/16 18:22:47 by jhalford ### ########.fr */
|
/* Updated: 2016/11/21 14:02:31 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,15 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putaddr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/21 15:13:34 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/21 15:13:35 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
|
|
||||||
void ft_putaddr(void *a)
|
void ft_putaddr(void *a)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue