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
0ce82927
Commit
0ce82927
authored
6 years ago
by
Lawrence Chung
Browse files
Options
Downloads
Plain Diff
Merge branch 'TeamB' of
https://gitlab.cas.mcmaster.ca/schankuc/2XB3
into TeamB
parents
cc9c3b31
b71fb87c
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/sort/QuickSelect.java
+18
-8
18 additions, 8 deletions
src/sort/QuickSelect.java
with
18 additions
and
8 deletions
src/sort/QuickSelect.java
+
18
−
8
View file @
0ce82927
...
...
@@ -7,18 +7,27 @@ import search.GeneralCompare;
public
class
QuickSelect
<
Key
,
Record
>
{
private
static
int
median
;
private
static
int
count
;
private
int
median
;
private
int
count
;
private
GeneralCompare
<
Key
>
gc
;
//
public
static
void
sort
(
Comparable
[]
a
)
{
public
static
void
main
(
String
[]
args
)
{
//{1, 2, 3, 4, 5, 6, 7, 8, 9} 5 is median.
int
[]
test
=
{
4
,
6
,
7
,
2
,
3
,
9
,
8
,
1
,
5
};
GeneralCompare
<
Integer
>
b1
;
b1
=
(
a1
,
a2
)
->
(
Integer
)
a1
-
(
Integer
)
a2
;
sort
<
Integer
,
Integer
>(
test
,
b1
);
}
public
void
sort
(
Comparable
<
Record
>[]
a
,
GeneralCompare
<
Key
>
genComp
)
{
//StdRandom.shuffle(a); // Eliminate dependence on input
gc
=
genComp
;
median
=
a
.
length
/
2
;
sort
(
a
,
0
,
a
.
length
-
1
);
}
public
static
void
sort
(
Comparable
[]
a
,
int
lo
,
int
hi
)
{
public
void
sort
(
Comparable
<
Record
>
[]
a
,
int
lo
,
int
hi
)
{
if
(
hi
<=
lo
)
return
;
int
j
=
partition
(
a
,
lo
,
hi
);
...
...
@@ -29,16 +38,16 @@ public class QuickSelect<Key, Record> {
return
;
}
private
static
int
partition
(
Comparable
[]
a
,
int
lo
,
int
hi
)
{
private
int
partition
(
Comparable
<
Record
>
[]
a
,
int
lo
,
int
hi
)
{
// Partition into a[lo..i-1], a[i], a[i+1..hi].
int
i
=
lo
,
j
=
hi
+
1
;
// left and right scan indices
Comparable
v
=
a
[
lo
];
// partitioning item
while
(
true
)
{
// Scan right, scan left, check for scan complete, and exchange.
while
(
less
(
a
[++
i
],
v
)
)
while
(
gc
.
compare
((
Value
)
a
[++
i
],
(
Value
)
v
)
<
0
)
if
(
i
==
hi
)
break
;
while
(
less
(
v
,
a
[--
j
]))
while
(
gc
.
compare
(
v
,
a
[--
j
])
<
0
)
if
(
j
==
lo
)
break
;
if
(
i
>=
j
)
...
...
@@ -55,4 +64,5 @@ public class QuickSelect<Key, Record> {
a
[
c
]
=
a
[
b
];
a
[
b
]
=
temp
;
}
}
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