Last day I thought about the different ways for sorting. Previously I was familiar with only two methods of sorting. When I searched in Wikipedia, I found several sorting algorithms. Here I am implementing some of the sorting algorithms the using Java.
1) Selection sorting
2) Bubble sorting
3) Insertion sorting
4) Merge sorting
5) Quick sorting
6) Shell sorting
Selection Sorting
a) the sublist of items already sorted, which is built up from left to right
b) the sublist of items remaining to be sorted that occupy the rest of the list.
Initially the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right. The sample java code is given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

public int[] selectionSort(int[] list){ // finding the length of the list int len = list.length; int j = 0; int tmp = 0; /* finding the smallest element in each iteration of inner loop * and arranging it from left to right thus finally, we will get a sorted list */ for(int i=0;i<len;i++){ j = i; for(int k = i;k<len;k++){ if(list[j]>list[k]){ j = k; } } tmp = list[i]; list[i] = list[j]; list[j] = tmp; } return list; } 
Bubble Sorting
Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements “bubble” to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, most of the other sorting algorithms are more efficient for large lists. The sample code using java is given below.

public int[] bubbleSort(int[] list){ int len = list.length; int temp = 0; for(int i = 0;i<len;i++){ for(int j = (len1);j>=(i+1);j){ if(list[j]<list[j1]){ temp = list[j]; list[j]=list[j1]; list[j1]=temp; } } } return list; } 
Insertion Sorting
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists. In this method we take one element and compares it with the rest of the elements in the list and fits into the position between the elements larger than and smaller than the actual element. Finally we will get a sorted list. Sample java code is given below.

public int[] InsertionSort(int[] list){ int len = list.length; int key = 0; int i = 0; for(int j = 1;j<len;j++){ key = list[j]; i = j1; while(i>=0 && list[i]>key){ list[i+1] = list[i]; list[i]=key; i = i1; } } return list; } 