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
0354358c
Commit
0354358c
authored
7 years ago
by
Haley Glavina
Browse files
Options
Downloads
Patches
Plain Diff
Introduced Null Pointer Exception at lambda function, sorts two array
parent
5c7e3d16
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/MergeSort.java
+25
-7
25 additions, 7 deletions
src/sort/MergeSort.java
with
25 additions
and
7 deletions
src/sort/MergeSort.java
+
25
−
7
View file @
0354358c
...
@@ -10,21 +10,22 @@ public class MergeSort{
...
@@ -10,21 +10,22 @@ public class MergeSort{
GeneralCompare
b1
;
GeneralCompare
b1
;
b1
=
(
a1
,
a2
)
->
(
Integer
)
a1
-
(
Integer
)
a2
;
b1
=
(
a1
,
a2
)
->
(
Integer
)
a1
-
(
Integer
)
a2
;
Integer
[]
test
=
{
3
,
4
,
2
,
1
,
5
,
7
,
9
,
10
};
Integer
[]
test
=
{
3
,
4
,
2
,
1
,
5
,
7
,
9
,
10
};
sort
(
test
,
0
,
Array
.
getLength
(
test
)
-
1
,
b1
);
//Integer[] test = {2, 1};
sort
(
test
,
0
,
test
.
length
-
1
,
b1
);
for
(
int
i
=
0
;
i
<
(
Array
.
getLength
(
test
)
-
1
)
;
i
++)
{
for
(
int
i
=
0
;
i
<
(
test
.
length
)
;
i
++)
{
System
.
out
.
println
(
test
[
i
]);
System
.
out
.
println
(
test
[
i
]);
}
}
}
}
public
static
void
sort
(
Comparable
[]
x
,
int
lo
,
int
hi
,
GeneralCompare
gc
)
{
public
static
void
sort
(
Comparable
[]
x
,
int
lo
,
int
hi
,
GeneralCompare
gc
)
{
aux
=
new
Comparable
[
Array
.
getL
ength
(
x
)
];
aux
=
new
Comparable
[
x
.
l
ength
];
sortWrapped
(
x
,
0
,
Array
.
getLength
(
x
)
-
1
,
gc
);
sortWrapped
(
x
,
lo
,
hi
,
gc
);
}
}
private
static
void
sortWrapped
(
Comparable
[]
x
,
int
lo
,
int
hi
,
GeneralCompare
gc
)
{
private
static
void
sortWrapped
(
Comparable
[]
x
,
int
lo
,
int
hi
,
GeneralCompare
gc
)
{
int
n
=
hi
-
lo
;
int
n
=
hi
-
lo
;
if
(
n
<
=
1
)
if
(
n
<
1
)
return
;
return
;
// Recursively sort each half of the array
// Recursively sort each half of the array
int
mid
=
lo
+
(
n
/
2
);
int
mid
=
lo
+
(
n
/
2
);
...
@@ -39,19 +40,36 @@ public class MergeSort{
...
@@ -39,19 +40,36 @@ public class MergeSort{
int
mid
=
lo
+
(
n
/
2
);
int
mid
=
lo
+
(
n
/
2
);
// Fill auxiliary array
// Fill auxiliary array
System
.
out
.
println
(
n
);
System
.
out
.
println
(
"lo, mid, hi: "
+
lo
+
", "
+
mid
+
", "
+
hi
);
for
(
int
k
=
lo
;
k
<=
hi
;
k
++){
for
(
int
k
=
lo
;
k
<=
hi
;
k
++){
aux
[
k
]
=
x
[
k
];
aux
[
k
]
=
x
[
k
];
}
}
int
i
=
lo
;
int
j
=
mid
+
1
;
for
(
int
k
=
0
;
k
<=
hi
;)
{
if
(
i
>
mid
)
x
[
k
++]
=
aux
[
j
++];
//All elems in first half already added to x
else
if
(
j
>
hi
)
x
[
k
++]
=
aux
[
i
++];
//All elems in second half already added to x
else
if
(
gc
.
compare
(
aux
[
i
],
aux
[
j
])
>
0
)
x
[
k
++]
=
aux
[
j
++];
else
x
[
k
++]
=
aux
[
i
++];
}
/*
int i = 0;
int i = 0;
// Merging two sorted arrays
// Merging two sorted arrays
while
(
(
lo
<=
mid
)
&
(
mid
<=
hi
)
)
{
while (
i
<=
n
) {
if (gc.compare(aux[lo], aux[mid]) > 0)
if (gc.compare(aux[lo], aux[mid]) > 0)
x[i++] = aux[mid++];
x[i++] = aux[mid++];
else
else
x[i++] = aux[lo++];
x[i++] = aux[lo++];
}
}
*/
/*
/*
// Is this portion sorting the aux array? Check
// Is this portion sorting the aux array? Check
...
...
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