-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathbubbleSort.java
More file actions
67 lines (54 loc) · 1.26 KB
/
bubbleSort.java
File metadata and controls
67 lines (54 loc) · 1.26 KB
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
62
63
64
65
66
67
import java.util.Scanner;
public class bubbleSort
{
public int[] insertData()
{
Scanner sn=new Scanner (System.in);
System.out.println("enter size of data list--> ");
int s;
s = sn.nextInt();
int d[];
d= new int[s];
for(int i=0;i<s;i++)
{
System.out.println("enter "+(i+1)+" data --> ");
d[i]=sn.nextInt();
}
return d;
}
public void bubbleSorting(int[] d,int s)
{
int temp=0;
for(int i=0;i<s;i++)
{
for(int j=0;j<s-1;j++)
{
if(d[j]>d[j+1])
{
temp=d[j];
d[j]=d[j+1];
d[j+1]=temp;
}
temp=0;
}
}
}
public void printSortedData(int s,int[] d)
{
System.out.println("Data after sorting-->");
for(int i=0;i<s;i++)
{
System.out.println(" "+d[i]);
}
}
public static void main(String[] args)
{
bubbleSort b=new bubbleSort();
int data[];
int size;
data=b.insertData();
size=data.length;
b.bubbleSorting(data,size);
b.printSortedData(size,data);
}
}