Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP_Bplus_Tree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hepia_2021-2022
Prog_Seq
TP_Bplus_Tree
Commits
8d9eeb2e
Commit
8d9eeb2e
authored
May 27, 2022
by
Alec
Browse files
Options
Downloads
Patches
Plain Diff
INSERT WORKS
parent
ff26e3fb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bp_tree.c
+108
-26
108 additions, 26 deletions
bp_tree.c
bp_tree.h
+1
-0
1 addition, 0 deletions
bp_tree.h
main.c
+38
-1
38 additions, 1 deletion
main.c
with
147 additions
and
27 deletions
bp_tree.c
+
108
−
26
View file @
8d9eeb2e
...
...
@@ -119,12 +119,42 @@ control bp_insert(node *nd, control val){
return
CONST_CONTR
;
}
node
*
bp_split_root
(
node
*
root
)
{
node
*
new
=
bp_create_node
();
node
*
rhs
=
bp_create_node
();
rhs
->
childs
[
0
]
=
root
->
childs
[
3
];
rhs
->
childs
[
1
]
=
root
->
childs
[
4
];
root
->
childs
[
3
]
=
NULL
;
root
->
childs
[
4
]
=
NULL
;
rhs
->
data
[
0
]
=
root
->
data
[
3
];
root
->
data
[
3
]
=
0
;
new
->
childs
[
0
]
=
root
;
new
->
childs
[
1
]
=
rhs
;
new
->
data
[
0
]
=
root
->
data
[
2
];
root
->
data
[
2
]
=
0
;
new
->
count
=
1
;
root
->
count
=
M
/
2
;
rhs
->
count
=
M
/
2
;
return
new
;
}
node
*
bp_insert_val
(
node
*
tree
,
int
val
)
{
control
test
=
bp_insert
(
tree
,
value_to_insert
(
val
));
if
(
test
.
rhs
!=
NULL
)
{
/*
if
(
!
bp_is_leaf
(
tree
))
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
if
(
tree
->
data
[
i
]
==
0
)
...
...
@@ -132,21 +162,36 @@ node* bp_insert_val(node* tree, int val)
tree
->
childs
[
i
+
1
]
=
test
.
rhs
;
tree
->
data
[
i
]
=
test
.
value
;
tree
->
count
++
;
break
;
}
}
/* GROS ICI SI LA RACINE N'EST PAS UNE FEUILLE ET QU'APRES AVOIR REMONTE UNE VALEUR LA RACINE EST PLEINE, IL FAUT SPLIT LA RACINE */
printf
(
"%d
\n
"
,
tree
->
count
);
if
(
tree
->
count
==
M
)
{
printf
(
"prout
\n
"
);
return
bp_split_root
(
tree
);
}
return
tree
;
}
}*/
tree
=
bp_create_node
();
tree
->
childs
[
0
]
=
test
.
lhs
;
tree
->
childs
[
1
]
=
test
.
rhs
;
tree
->
data
[
0
]
=
test
.
value
;
tree
->
count
=
M
/
2
;
tree
->
count
=
1
;
}
return
tree
;
}
void
bp_destroy
(
node
*
nd
)
{
if
(
nd
==
NULL
)
return
;
if
(
!
bp_is_leaf
(
nd
))
{
for
(
int
i
=
0
;
i
<
M
;
i
++
)
...
...
@@ -158,25 +203,62 @@ void bp_destroy(node *nd)
free
(
nd
);
}
void
bp_print
(
node
*
nd
,
int
depth
)
void
bp_print_as_ll
(
node
*
nd
)
{
if
(
nd
==
NULL
)
{
printf
(
"NULL
\n
"
);
return
;
}
if
(
!
bp_is_leaf
(
nd
))
{
for
(
int
i
=
0
;
i
<
nd
->
count
;
i
++
){
//printf("i = %d\n", i);
if
(
!
bp_is_leaf
(
nd
)){
//printf("is not leaf = %d\n", d);
return
bp_print_as_ll
(
nd
->
childs
[
0
]);
}
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
printf
(
" %d |"
,
nd
->
data
[
i
]);
if
(
nd
->
data
[
i
+
1
]
==
0
)
{
printf
(
"->"
);
return
bp_print_as_ll
(
nd
->
next
);
}
}
}
void
bp_print
(
node
*
nd
,
int
depth
)
{
if
(
bp_is_leaf
(
nd
))
{
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
printf
(
" "
);
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
printf
(
" %d |"
,
nd
->
data
[
i
]);
if
(
nd
->
data
[
i
+
1
]
==
0
)
break
;
}
printf
(
"
\n
"
);
return
;
}
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
printf
(
"
\n
"
);
bp_print
(
nd
->
childs
[
i
],
depth
+
1
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
for
(
int
k
=
0
;
k
<
depth
;
++
k
){
for
(
int
i
=
0
;
i
<
depth
;
i
++
)
printf
(
" "
);
}
printf
(
" %d |"
,
nd
->
data
[
i
]);
printf
(
"| %d |"
,
nd
->
data
[
i
]);
}
if
(
nd
->
data
[
i
+
1
]
==
0
)
{
printf
(
"
\n
"
);
return
bp_print
(
nd
->
childs
[
i
+
1
],
depth
+
1
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
bp_tree.h
+
1
−
0
View file @
8d9eeb2e
...
...
@@ -25,4 +25,5 @@ void bp_destroy(node *nd);
control
bp_insert
(
node
*
nd
,
control
val
);
node
*
bp_create_node
();
node
*
bp_insert_val
(
node
*
tree
,
int
val
);
void
bp_print_as_ll
(
node
*
nd
);
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main.c
+
38
−
1
View file @
8d9eeb2e
...
...
@@ -4,6 +4,31 @@
int
main
(){
/*
node *test = bp_create_node();
test->count = 1;
test->data[0] = 3;
for (int i = 0; i < 2; i++)
{
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
);
...
...
@@ -23,7 +48,19 @@ int main(){
printf
(
"|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
8
);
bp_print
(
tree
,
0
);
printf
(
"|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
9
);
bp_print
(
tree
,
0
);
printf
(
"|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
10
);
bp_print
(
tree
,
0
);
printf
(
"|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
11
);
bp_print
(
tree
,
0
);
printf
(
"|||||||||
\n
"
);
tree
=
bp_insert_val
(
tree
,
12
);
bp_print
(
tree
,
0
);
bp_print_as_ll
(
tree
);
bp_destroy
(
tree
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment