FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Essentials/BubbleSort.java at master · Sayantan7D/Java-Essentials · GitHub
Sayantan7D
/
Java-Essentials
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Essentials
/
BubbleSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
61 lines (48 loc) · 1.54 KB
Breadcrumbs
Java-Essentials
/
BubbleSort.java
Copy path
File metadata and controls
61 lines (48 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import
java
.
util
.
Scanner
;
public
class
BubbleSort
{
private
static
Scanner
sc
=
new
Scanner
(
System
.
in
);
public
static
int
[]
getelements
(
int
capacity
){
int
[]
array
=
new
int
[
capacity
];
System
.
out
.
println
(
"
\n
Enter "
+
capacity
+
" elements -
\n
"
);
for
(
int
i
=
0
;
i
<
capacity
;
i
++){
array
[
i
]=
sc
.
nextInt
();
}
return
array
;
}
public
static
int
[]
sortelements
(
int
[]
array
,
int
n
){
int
[]
sortedarr
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
sortedarr
[
i
]=
array
[
i
];
boolean
flag
=
true
;
int
temp
;
while
(
flag
){
flag
=
false
;
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++){
if
(
sortedarr
[
i
]<
sortedarr
[
i
+
1
]){
temp
=
sortedarr
[
i
];
sortedarr
[
i
]=
sortedarr
[
i
+
1
];
sortedarr
[
i
+
1
]=
temp
;
flag
=
true
;
}
}
}
return
sortedarr
;
}
public
static
void
printarray
(
int
[]
arr
){
System
.
out
.
println
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
System
.
out
.
print
(
arr
[
i
]+
" "
);
System
.
out
.
println
(
"
\n
"
);
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
"
\n
Enter the total number of elements in the array - "
);
int
n
=
sc
.
nextInt
();
int
[]
arr
=
new
int
[
n
];
arr
=
getelements
(
n
);
System
.
out
.
println
(
"
\n
Input Array -
\n
"
);
printarray
(
arr
);
int
[]
sortedarr
=
sortelements
(
arr
,
n
);
System
.
out
.
println
(
"
\n
Sorted Array -
\n
"
);
printarray
(
sortedarr
);
}
}
Back
|
FazBrowse Home
|
New Git URL