Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Edmunds Žagars
Java_course_final
Commits
bc7608b1
Commit
bc7608b1
authored
Mar 15, 2018
by
edmundszagars
Browse files
Adding "BubbleSort" class
parent
9671cc23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
src/Main.java
src/Main.java
+9
-2
src/sorting_algorithms/BubbleSort.java
src/sorting_algorithms/BubbleSort.java
+24
-0
No files found.
src/Main.java
View file @
bc7608b1
import
sorting_algorithms.BubbleSort
;
import
java.io.FileNotFoundException
;
import
java.util.Arrays
;
...
...
@@ -5,7 +7,12 @@ public class Main {
public
static
void
main
(
String
[]
args
)
throws
FileNotFoundException
{
GetDataFromCSV
get
=
new
GetDataFromCSV
();
get
.
setnFileLocation
(
"data2.csv"
);
for
(
int
i
=
0
;
i
<
get
.
getDataFromCSV
().
size
();
i
++)
System
.
out
.
println
(
get
.
getDataFromCSV
().
get
(
i
).
size
());
Object
[]
arrray
=
get
.
getDataFromCSV
().
get
(
1
).
toArray
();
double
[]
data
=
new
double
[
arrray
.
length
];
for
(
int
i
=
0
;
i
<
arrray
.
length
;
i
++){
data
[
i
]
=
(
double
)
arrray
[
i
];
}
System
.
out
.
println
(
Arrays
.
toString
(
BubbleSort
.
bubbleSort
(
data
)));
}
}
src/sorting_algorithms/BubbleSort.java
0 → 100644
View file @
bc7608b1
package
sorting_algorithms
;
public
class
BubbleSort
{
public
static
double
[]
bubbleSort
(
double
[]
array
)
{
int
n
=
array
.
length
;
int
k
;
for
(
int
m
=
n
;
m
>=
0
;
m
--)
{
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++)
{
k
=
i
+
1
;
if
(
array
[
i
]
>
array
[
k
])
{
swapNumbers
(
i
,
k
,
array
);
}
}
}
return
array
;
}
private
static
void
swapNumbers
(
int
i
,
int
k
,
double
[]
array
)
{
double
tmp
;
tmp
=
array
[
i
];
array
[
i
]
=
array
[
k
];
array
[
k
]
=
tmp
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment