-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble.java
More file actions
39 lines (37 loc) · 795 Bytes
/
Bubble.java
File metadata and controls
39 lines (37 loc) · 795 Bytes
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
import java.io.*;
import java.util.Scanner;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Bubble
{
public static void shorting(int n)
{
int a[] = {10,56,2,23,850,556,23};
int temp; // Here Temp variable is for to transfer a[i] value into (a[i+1]) it means the next address of a[i].
for(int k=0;k<n-1;k++)
{
for(int i=0;i<n-k-1;i++)
{
if(a[i] > a[i+1])
{
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
}
}
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
public static void main(String[] arg)
{
Scanner scan=new Scanner(System.in);
int n = scan.nextInt();
System.out.println("Before Shorting");
shorting(n);
System.out.println("After Shorting");
}
}