Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BubbleSort
- {
- public static void main(String[] args)
- {
- int[] list = new int[10];
- for(int i = 0; i < list.length; i++)
- {
- list[i] = (int) (Math.random() * 100) + 1;
- }
- list = bubbleSort(list);
- for(int i = 0; i < list.length; i++)
- {
- if(i != list.length - 1)
- {
- System.out.print(list[i] + ", ");
- } else
- {
- System.out.print(list[i]);
- }
- }
- }
- static int[] bubbleSort(int[] list)
- {
- int holder;
- boolean flag = true;
- while(flag)
- {
- flag = false;
- for(int i = 0; i < list.length - 1; i++)
- {
- if(list[i] > list[i + 1])
- {
- holder = list[i];
- list[i] = list[i + 1];
- list[i + 1] = holder;
- flag = true;
- }
- }
- }
- return list;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement