Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Rudolf
/
huffman
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6457da18
authored
Nov 16, 2016
by
Rudolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add print tree support (horizontal)
Horizontal tree print fills all my needs
parent
a169c230
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
print_helper.c
print_helper.h
print_helper.c
View file @
6457da18
...
...
@@ -44,3 +44,32 @@ void print_char(char c)
break
;
}
}
void
print_tree
(
struct
tree
*
parent
)
{
int
level
=
1
;
while
(
parent
->
left
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
level
;
i
++
)
{
printf
(
" "
);
}
if
(
parent
->
right
)
print_char
(
parent
->
right
->
ch
);
for
(
int
i
=
0
;
i
<
level
-
1
;
i
++
)
{
printf
(
" "
);
}
printf
(
"o
\n
"
);
for
(
int
i
=
0
;
i
<
level
;
i
++
)
{
printf
(
" "
);
}
if
(
parent
->
left
&&
parent
->
left
->
ch
!=
0
)
print_char
(
parent
->
left
->
ch
);
else
printf
(
"o
\n
"
);
level
+=
2
;
parent
=
parent
->
left
;
}
}
print_helper.h
View file @
6457da18
/* I DO NOT OWN THIS CODE. */
/* From http://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format?page=2&tab=votes#tab-top */
#include "tree.h"
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define for_endian(size) for (int i = 0; i < size; ++i)
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
...
...
@@ -18,3 +20,4 @@ void __printb(void *value, size_t size);
})
void
print_char
(
char
c
);
void
print_tree
(
struct
tree
*
parent
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment