Skip to main content

Posts

Showing posts from August, 2014

Sorting Algorithms

Java Implementation for Sortings: Bubble Sort: import java.util.Scanner; public class BubbleSort {       public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("input size"); int n = scan.nextInt(); int[] ar = new int[n]; System.out.println("input elements"); for (int i = 0; i < ar.length; i++) { ar[i] = scan.nextInt(); } bubbleSort(ar); for (int i = 0; i < ar.length; i++) { System.out.print(ar[i]+"\t"); } System.out.println(); scan.close(); } private static void bubbleSort(int[] ar) { // TODO Auto-generated method stub int temp = 0; for (int i = 0; i < ar.length; i++) { for (int j = 1; j < (ar.length-i); j++) { if(ar[j-1]>ar[j]){ te...