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
0ecb2e66
Commit
0ecb2e66
authored
7 years ago
by
Lawrence Chung
Browse files
Options
Downloads
Patches
Plain Diff
Added size
parent
73a45277
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/search/GeneralCompare.java
+5
-0
5 additions, 0 deletions
src/search/GeneralCompare.java
src/search/Node.java
+6
-2
6 additions, 2 deletions
src/search/Node.java
src/search/RedBlackTree.java
+50
-9
50 additions, 9 deletions
src/search/RedBlackTree.java
with
61 additions
and
11 deletions
src/search/GeneralCompare.java
0 → 100644
+
5
−
0
View file @
0ecb2e66
package
search
;
public
interface
GeneralCompare
<
T
>
{
public
int
compare
(
Comparable
<
T
>
a1
,
Comparable
<
T
>
a2
);
}
This diff is collapsed.
Click to expand it.
src/search/Node.java
+
6
−
2
View file @
0ecb2e66
...
...
@@ -30,7 +30,7 @@ public class Node<Key, Value, T>{
return
this
.
val
;
}
public
void
val
(
Value
val
){
public
void
val
(
Comparable
<
T
>[]
val
){
this
.
val
=
val
;
}
...
...
@@ -50,10 +50,14 @@ public class Node<Key, Value, T>{
this
.
right
=
right
;
}
public
int
N
(){
public
int
n
(){
return
this
.
n
;
}
public
void
n
(
int
n
){
this
.
n
=
n
;
}
public
boolean
color
(){
return
this
.
color
;
}
...
...
This diff is collapsed.
Click to expand it.
src/search/RedBlackTree.java
+
50
−
9
View file @
0ecb2e66
...
...
@@ -4,35 +4,76 @@ public class RedBlackTree<Key, Value> {
private
Node
root
;
private
int
size
();
private
<
T
>
int
size
(
Comparable
<
T
>[]
val
){
return
val
.
length
;
}
public
<
T
>
void
put
(
Key
key
,
Comparable
<
T
>[]
val
){
root
=
put
(
root
,
key
,
val
);
root
.
color
(
false
);
}
private
<
T
>
Node
put
(
Node
h
,
Key
key
,
Comparable
<
T
>[]
val
){
Node
root
=
new
Node
(
key
,
val
,
n
,
color
);
private
boolean
isRed
(
Node
x
){
return
x
.
color
();
}
public
Node
rotateLeft
(
Node
h
){
Node
x
=
h
.
right
();
h
.
right
(
x
.
left
());
x
.
left
(
h
);
x
.
color
(
h
.
color
());
h
.
color
(
true
);
x
.
n
(
h
.
n
());
h
.
n
(
1
+
size
(
h
.
left
())
+
size
(
h
.
right
()));
return
x
;
}
public
Node
rotateRight
(
Node
h
){
Node
x
=
h
.
left
();
h
.
left
(
x
.
right
());
x
.
right
(
h
);
x
.
color
(
h
.
color
());
h
.
color
(
true
);
x
.
n
(
h
.
n
());
h
.
n
(
1
+
size
(
h
.
left
())
+
size
(
h
.
right
()));
return
x
;
}
private
void
flipColors
(
Node
h
){
if
(
h
.
left
()
!=
null
&&
h
.
right
()
!=
null
){
h
.
left
().
color
(
false
);
h
.
right
().
color
(
false
);
h
.
color
(
true
);
}
}
private
<
T
>
Node
put
(
Node
h
,
Key
key
,
Comparable
<
T
>[]
val
,
GeneralCompare
<
T
>
gc
){
int
n
=
size
(
h
);
Node
root
=
new
Node
(
key
,
val
,
n
,
true
);
if
(
h
==
null
)
return
new
Node
(
key
,
val
,
1
,
true
);
int
cmp
=
key
.
compareTo
(
h
.
key
());
if
(
cmp
<
0
)
h
.
left
(
put
(
h
.
left
(),
key
,
val
));
h
.
left
(
put
(
h
.
left
(),
key
,
val
,
gc
));
else
if
(
cmp
>
0
)
h
.
right
(
put
(
h
.
right
(),
key
,
val
));
h
.
right
(
put
(
h
.
right
(),
key
,
val
,
gc
));
else
h
.
val
(
val
);
if
(
isRed
(
h
.
right
)
&&
!
isRed
(
h
.
left
))
if
(
isRed
(
h
.
right
()
)
&&
!
isRed
(
h
.
left
()
))
h
=
rotateLeft
(
h
);
if
(
isRed
(
h
.
left
)
&&
isRed
(
h
.
left
.
left
))
if
(
isRed
(
h
.
left
()
)
&&
isRed
(
h
.
left
()
.
left
()
))
h
=
rotateRight
(
h
);
if
(
isRed
(
h
.
left
)
&&
isRed
(
h
.
right
))
if
(
isRed
(
h
.
left
()
)
&&
isRed
(
h
.
right
()
))
flipColors
(
h
);
h
.
n
=
size
(
h
.
left
)
+
size
(
h
.
right
)
+
1
;
h
.
n
(
size
(
h
.
left
())
+
size
(
h
.
right
())
+
1
);
return
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