/* * To change this template, choose Tools | Templates * and - TopicsExpress



          

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author ccs1105-34 */ import java.util.Scanner; class Sorting { public static void main(String[] args) { int n, Menu, c, d, swap, option; boolean doAgain = true; while(doAgain){ System.out.print(\nSelect transaction+\n[1] Bubble Sort+\n[2] Selection Sort+\n[3] Insertion Sort+\n[4] Exit+\n); Scanner optn=new Scanner(System.in); option=optn.nextInt(); switch(option){ case 1: Sorting.blossom(); break; case 2: Sorting.buttercup(); break; case 3: Sorting.blossom(); break; case 4: System.exit(0); default: System.out.print(Wrong choice!!!); } System.out.print (\nDo you want to do it again?+\n[1]Yes+\n[0]No+\n); Scanner optn2=new Scanner(System.in); int doAgainInt=optn2.nextInt(); if(doAgainInt==1){ doAgain=true; }else if(doAgainInt==0){ System.out.print(\nBYE!!! :)\n); doAgain=false; } else System.out.print(Wrong Choice!!!); } } public static void bubbles(){ int N1, N2, N3, swap, option; Scanner in = new Scanner(System.in); System.out.println(Input number of integers to sort); N1 = in.nextInt(); int array[] = new int[N1]; System.out.println(Enter + N1 + integers); for (N2 = 0; N2 < N1; N2++) array[N2] = in.nextInt(); for (N2 = 0; N2 < ( N1 - 1 ); N2++) { for (N3 = 0; N3 < N1 - N2 - 1; N3++) { if (array[N3] > array[N3+1]){ swap = array[N3]; array[N3] = array[N3+1]; array[N3+1] = swap; } } } System.out.println(Bubbles); for (N2 = 0; N2 < N1; N2++) System.out.println(array[N2]); } public static void buttercup(){ int a, i, j; Scanner in = new Scanner(System.in); System.out.println(Input number of integers to sort); a = in.nextInt(); int array[] = new int[a]; System.out.println(Enter + a + integers); for (i = 0; i < a; i++) array[i] = in.nextInt(); int min; for (i = 0; i < array.length; i++) { min = i; for (j = i + 1; j < array.length; j++) { if (array[j] < array[min]) { min = j; } } if (min != i) { final int temp = array[i]; array[i] = array[min]; array[min] = temp; } } System.out.println(Selection); for (i = 0; i < a; i++) System.out.print(array[i]+ ); } public static void blossom(){ int n,c; Scanner in=new Scanner(System.in); System.out.println(Input number of integers to sort); n=in.nextInt(); int array[]=new int[n]; System.out.println(Enter + n + integers); for (c=0;c0; inner--){ if(array[inner]
Posted on: Sat, 09 Aug 2014 01:15:21 +0000

Recently Viewed Topics




© 2015