-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSort.java
36 lines (35 loc) · 1016 Bytes
/
BubbleSort.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
import java.util.ArrayList;
import java.util.Random;
/**
* Created by nano on 03.11.15.
*/
public class BubbleSort {
public static void main(String[] args){
String bunchOfWords = "Read the file";
char[] charArray2 = bunchOfWords.toCharArray();
for(int i = 0; i < charArray2.length; i++){
System.out.println((int)charArray2[i]);
}
ArrayList<Integer> tmp = new ArrayList<Integer>();
int size = 10;
for(int i = 0; i < size ; i++){
Random rand = new Random();
int randomNumber = rand.nextInt(100);
tmp.add(randomNumber);
}
System.out.println(tmp);
for (int i = 0; i<size-1;i++){
for(int j = 0; j<size-1;j++){
int n = tmp.get(j);
int n1 = tmp.get(j+1);
if (n>n1){
tmp.remove(j);
tmp.add(j,n1);
tmp.remove(j+1);
tmp.add(j+1,n);
}
}
}
System.out.println(tmp);
}
}