-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patharray_bubble_s.java
More file actions
38 lines (37 loc) · 922 Bytes
/
array_bubble_s.java
File metadata and controls
38 lines (37 loc) · 922 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
import java.util.Scanner;
public class array_bubble_s
{//ascending
void bubblesort()
{
String c[],temp;
int i,j,n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements");
n=sc.nextInt();
c=new String[n];
System.out.println("Enter "+n+" words");
for(i=0;i<n;i++)
{
c[i]=sc.next();
}
for(i=0;i<n;i++)
{
for(j=0;j<(n-1);j++)
{
if(c[j].compareTo(c[j+1])>0)
{
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
System.out.print(c[i]+" ");
}
public static void main(String args[])
{
array_bubble_s obj=new array_bubble_s();
obj.bubblesort();
}
}