FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/selectionsort.java at master · Ayomal98/Java-Programs · GitHub
Ayomal98
/
Java-Programs
Public
forked from
codec-akash/DSA-PS-Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
selectionsort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (37 loc) · 998 Bytes
Breadcrumbs
Java-Programs
/
selectionsort.java
Copy path
File metadata and controls
41 lines (37 loc) · 998 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import
java
.
io
.*;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Scanner
;
// Java program for implementation of Selection Sort
class
SelectionSort
{
void
sorting
(
ArrayList
<
Integer
>
arr
)
{
int
n
=
arr
.
size
();
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++)
{
int
min_idx
=
i
;
for
(
int
j
=
i
+
1
;
j
<
n
;
j
++)
if
(
arr
.
get
(
j
) <
arr
.
get
(
min_idx
))
min_idx
=
j
;
int
temp
=
arr
.
get
(
min_idx
);
arr
.
set
(
min_idx
,
arr
.
get
(
i
));
arr
.
set
(
i
,
temp
);
}
}
public
static
void
main
(
String
args
[])
throws
IOException
{
SelectionSort
obj
=
new
SelectionSort
();
String
pathToFile
=
"./Sorting/unsorted.txt"
;
File
unsorted
=
new
File
(
pathToFile
);
Scanner
sc
=
new
Scanner
(
unsorted
);
sc
.
useDelimiter
(
","
);
ArrayList
<
Integer
>
arr
=
new
ArrayList
<
Integer
>();
while
(
sc
.
hasNext
()){
arr
.
add
(
sc
.
nextInt
());
}
obj
.
sorting
(
arr
);
System
.
out
.
println
(
"Sorted array"
);
System
.
out
.
println
(
arr
);
sc
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL