Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class BubbleSort {
- static void bubbleSort(int array []){
- int n = array.length ;
- int temp = 0;
- for(int i=0; i < n; i++){
- for(int j=1; j < (n-i); j++){
- if(array[j-1] > array[j]){
- //swap elements
- temp = array[j-1];
- array[j-1] = array[j];
- array[j] = temp;
- }
- }
- }
- }
- }
- ******************************************************************************************
- public class SelectionSort {
- public static void selectionSort(int[] array){
- for (int i = 0; i < array.length - 1; i++)
- {
- int index = i;
- for (int j = i + 1; j < array.length; j++){
- if (array[j] < array[index]){
- index = j;//searching for lowest index
- }
- }
- int smallerNumber = array[index];
- array[index] = array[i];
- array[i] = smallerNumber;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement