Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
root-devvoo
Java-Data_Structure
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Java-Data_Structure
/
Chapter1
/
src
/
Code14.java
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
33 lines (31 loc) · 1.29 KB
main
Breadcrumbs
Java-Data_Structure
/
Chapter1
/
src
/
Code14.java
Copy path
Top
File metadata and controls
Code
Blame
33 lines (31 loc) · 1.29 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
import
java
.
util
.
Scanner
;
// 정렬을 다뤄본다.
/*
* 사용자로부터 n개의 정수를 입력받은 후
* 오름차순으로 정렬(sort)하여 출력하는 코드이다.
*/
public
class
Code14
{
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
int
[]
data
=
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++)
data
[
i
] =
sc
.
nextInt
();
sc
.
close
();
// 버블정렬(bubblesort) 알고리즘
for
(
int
i
=
n
-
1
;
i
>
0
;
i
--) {
// i는 sort 대상인 마지막 데이터의 배열 인덱스를 표시
// data[0] ~ data[i] 중에서 (다른 값들이 어떻게 되건 상관하지 않고) 최대값을 data[i] 위치로 몰아가는 일을 함
for
(
int
j
=
0
;
j
<
i
;
j
++) {
// j는 i-1까지만 가면 된다.
if
(
data
[
j
] >
data
[
j
+
1
]) {
// data[j]가 data[j+1]보다 크면 자리를 바꾼다.
// swap
int
tmp
=
data
[
j
];
// 스왑을 할 때는 잠깐 임시로 다른 곳에 써두고
data
[
j
] =
data
[
j
+
1
];
// 그러면 그 자리에 내가 다른 값을 덮더라도 상관이 없으니까 그 자리에 쓰고,
data
[
j
+
1
] =
tmp
;
// 다른쪽에는 임시로 저장해뒀던 값을 쓰면 두 값의 교환이 이루어진다.
}
}
}
System
.
out
.
println
(
"Sorted data: "
);
for
(
int
i
=
0
;
i
<
n
;
i
++)
System
.
out
.
println
(
data
[
i
]);
}
}
You can’t perform that action at this time.