-
Notifications
You must be signed in to change notification settings - Fork 1k
/
BeadSort.java
54 lines (51 loc) · 1.15 KB
/
BeadSort.java
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
import java.util.*;
class sorting
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int indexI,indexJ,arrayLength,temp,indexK;
System.out.println("Enter the length of array");
arrayLength=sc.nextInt();
int array[]=new int[arrayLength];
System.out.println("Enter array elements");
for(indexI=0;indexI<arrayLength;indexI++)
array[indexI]=sc.nextInt();
indexI=0;indexJ=1;
while(indexI<arrayLength-2)
{ indexJ=indexI+1;
while(array[indexI]<=array[indexJ])
{ if(indexI==arrayLength-2)
break;
indexI++;
indexJ=indexI+1;
}
if(array[indexI]>array[indexJ])
{
temp=array[indexJ];
array[indexJ]=array[indexI];
array[indexI]=temp;
indexI=0;
continue;
}
}
for(indexI=0;indexI<arrayLength;indexI++)
System.out.println(array[indexI]+" ");
}
}
/*
Input :
Enter the length of array
5
Enter array elements
1
2
3
1
1
Output :
1
1
1
2
3 */