Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2XB3FinalProject
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christopher Schankula
2XB3FinalProject
Commits
792c7301
Commit
792c7301
authored
7 years ago
by
Lawrence Chung
Browse files
Options
Downloads
Patches
Plain Diff
Added testing main method, changed to static
parent
7750df41
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/search/RedBlackTree.java
+16
-10
16 additions, 10 deletions
src/search/RedBlackTree.java
with
16 additions
and
10 deletions
src/search/RedBlackTree.java
+
16
−
10
View file @
792c7301
...
...
@@ -3,26 +3,32 @@ package search;
public
class
RedBlackTree
<
Key
,
Value
>
{
public
static
void
main
(
String
[]
args
)
{
int
[]
x
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
GeneralCompare
<
Integer
>
b1
;
b1
=
(
a1
,
a2
)
->
(
Integer
)
a1
-
(
Integer
)
a2
;
Integer
[]
x
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
for
(
int
i
=
0
;
i
<=
x
.
length
;
i
++){
put
(
x
[
i
],
x
,
b1
);
}
}
private
Node
root
;
private
static
Node
root
;
private
<
T
>
int
size
(
Node
h
){
private
static
<
T
>
int
size
(
Node
h
){
return
h
.
n
();
}
public
<
T
>
void
put
(
Comparable
<
T
>
key
,
Comparable
<
T
>[]
val
,
GeneralCompare
gc
){
public
static
<
T
>
void
put
(
Comparable
<
T
>
key
,
Comparable
<
T
>[]
val
,
GeneralCompare
gc
){
root
=
put
(
root
,
key
,
val
,
gc
);
root
.
color
(
false
);
System
.
out
.
println
(
root
.
key
());
System
.
out
.
println
(
root
.
val
());
}
private
boolean
isRed
(
Node
x
){
private
static
boolean
isRed
(
Node
x
){
return
x
.
color
();
}
public
Node
rotateLeft
(
Node
h
){
public
static
Node
rotateLeft
(
Node
h
){
Node
x
=
h
.
right
();
h
.
right
(
x
.
left
());
x
.
left
(
h
);
...
...
@@ -33,7 +39,7 @@ public class RedBlackTree<Key, Value> {
return
x
;
}
public
Node
rotateRight
(
Node
h
){
public
static
Node
rotateRight
(
Node
h
){
Node
x
=
h
.
left
();
h
.
left
(
x
.
right
());
x
.
right
(
h
);
...
...
@@ -45,7 +51,7 @@ public class RedBlackTree<Key, Value> {
}
private
void
flipColors
(
Node
h
){
private
static
void
flipColors
(
Node
h
){
if
(
h
.
left
()
!=
null
&&
h
.
right
()
!=
null
){
h
.
left
().
color
(
false
);
h
.
right
().
color
(
false
);
...
...
@@ -53,7 +59,7 @@ public class RedBlackTree<Key, Value> {
}
}
private
<
T
>
Node
put
(
Node
h
,
Comparable
<
T
>
key
,
Comparable
<
T
>[]
val
,
GeneralCompare
<
T
>
gc
){
private
static
<
T
>
Node
put
(
Node
h
,
Comparable
<
T
>
key
,
Comparable
<
T
>[]
val
,
GeneralCompare
<
T
>
gc
){
int
n
=
size
(
h
);
...
...
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
register
or
sign in
to comment