Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bubble Sort using Java.#159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Sirajmolla merged 1 commit intocoder2hacker:mainfromPoulami-17:main
Oct 3, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletionsBubbleSort1.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
import java.util.*;
class BubbleSort1{
// Bubble Sort Function
public static void BubbleSort(int arr[]){
for(int i=0;i<=arr.length-1;i++){
// Inner loop to visit two adjacent elements
for(int j=0;j<arr.length-1-i;j++){
// Swaping two adjacent elements
if (arr[j]>arr[j+1]){
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
}
// Function to print Array
public static void PrintArray(int arr[]){
for (int i=0;i<arr.length;i++)
System.out.print(arr[i]+" ");
}

public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int arr[]=new int[5];
for(int i=0;i<arr.length;i++)
arr[i]=sc.nextInt();
sc.close();

BubbleSort(arr);
PrintArray(arr);
}
}

[8]ページ先頭

©2009-2025 Movatter.jp