Skip to content
Snippets Groups Projects
Commit 3fc3d0df authored by Alec's avatar Alec
Browse files

modified print func

parent 6de38c99
Branches
No related tags found
No related merge requests found
...@@ -261,13 +261,14 @@ void bp_print_as_ll(node *root) ...@@ -261,13 +261,14 @@ void bp_print_as_ll(node *root)
return bp_print_as_ll(root->childs[0]); return bp_print_as_ll(root->childs[0]);
} }
printf("|");
// print every values in the node until hitting 0, then we can get on the next node // print every values in the node until hitting 0, then we can get on the next node
for (int i = 0; i < M; i++) for (int i = 0; i < M; i++)
{ {
printf(" %d |", root->data[i]); printf(" %d |", root->data[i]);
if (root->data[i+1] == 0) if (root->data[i+1] == 0)
{ {
printf("->"); printf(" -> ");
return bp_print_as_ll(root->next); return bp_print_as_ll(root->next);
} }
} }
...@@ -288,23 +289,20 @@ void bp_print(node *root, int depth) ...@@ -288,23 +289,20 @@ void bp_print(node *root, int depth)
if (root->data[i+1] == 0) if (root->data[i+1] == 0)
break; break;
} }
printf("\n");
return; return;
} }
for (int i = 0; i < M; i++) for (int i = 0; i < M; i++)
{ {
printf("\n");
bp_print(root->childs[i], depth + 1); bp_print(root->childs[i], depth + 1);
printf("\n");
for (int i = 0; i < depth; i++) for (int i = 0; i < depth; i++)
printf(" "); printf(" ");
printf(" %d |", root->data[i]);
printf(" %d |\n", root->data[i]);
if (root->data[i+1] == 0) if (root->data[i+1] == 0)
{
printf("\n");
return bp_print(root->childs[i+1], depth + 1); return bp_print(root->childs[i+1], depth + 1);
}
} }
} }
\ No newline at end of file
#ifndef _BP_TREE_C_ #ifndef _BP_TREE_C_
#define _BP_TREE_C_ #define _BP_TREE_C_
#define M 5 #define M 4
#include <stdlib.h> #include <stdlib.h>
typedef struct node{ typedef struct node{
......
#include "bp_tree.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "bp_tree.h"
int main(){
/*
node *test = bp_create_node();
test->count = 1; int
test->data[0] = 3; main ()
for (int i = 0; i < 2; i++) {
{ node *tree = bp_create_node ();
test->childs[i] = bp_create_node();
test->childs[i]->count = 1;
test->childs[i]->data[0] = 3;
for (int y = 0; y < 2; y++)
{
test->childs[i]->childs[y] = bp_create_node();
for (int z = 0; z < 2; z++)
{
test->childs[i]->childs[y]->data[z] = 3;
}
test->childs[i]->childs[y]->count = 2;
}
}
bp_print(test, 0);
bp_destroy(test);*/
node *tree = bp_create_node();
tree = bp_insert_val(tree, 3); tree = bp_insert_val (tree, 3);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 6); tree = bp_insert_val (tree, 6);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 5); tree = bp_insert_val (tree, 5);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 4); tree = bp_insert_val (tree, 4);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 7); tree = bp_insert_val (tree, 7);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 8); tree = bp_insert_val (tree, 8);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 9); tree = bp_insert_val (tree, 9);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 10); tree = bp_insert_val (tree, 10);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 11); tree = bp_insert_val (tree, 11);
bp_print(tree, 0); bp_print (tree, 0);
printf("|||||||||\n"); printf ("\n|||||||||\n");
tree = bp_insert_val(tree, 12); tree = bp_insert_val (tree, 12);
bp_print(tree, 0); bp_print (tree, 0);
bp_print_as_ll(tree); printf ("\n|||||||||\n");
bp_destroy(tree); bp_print_as_ll (tree);
return 0; bp_destroy (tree);
return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment