plzz help me how can i do the 3 sorting in 1 program user input
using bufferedReader plzzz...
bubble sort
slection sort
insertion sort

Edited 5 Years Ago by rayvarde: n/a

3 sorting problem
1.bubble sort
2.selection sort
3.insertion sort

how can i do that in 1 program.
the 3 sorting problem is user input and i like to create 1 program same user input..


example: what sorting you want to run
i chose: number 1.
and after number 1. i like to chose again number 3.

i hope u can help sir plzzz...

i used this example for bubble sorting i hope it helps

public class bubbleSort{
  public static void main(String a[]){
  int i;
  int array[] = {12,9,4,99,120,1,3,10};
  System.out.println("Values Before the sort:\n");
  for(i = 0; i < array.length; i++)
  System.out.print( array[i]+"  ");
  System.out.println();
  bubble_srt(array, array.length);
  System.out.print("Values after the sort:\n");
  for(i = 0; i <array.length; i++)
  System.out.print(array[i]+"  ");
  System.out.println();
  System.out.println("PAUSE");
  }

  public static void bubble_srt( int a[], int n ){
  int i, j,t=0;
  for(i = 0; i < n; i++){
  for(j = 1; j < (n-i); j++){
  if(a[j-1] > a[j]){
  t = a[j-1];
  a[j-1]=a[j];
  a[j]=t;
  }
  }
  }
  }
}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format all code that you post.

Ok..
Read the user input (elements that are to be sorted ) into an array..
Then read the choice of the menu..

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int choice=Integer.parseInt(br.readLine());

Now using switch - case , write your actual sorting technique code in the appropriate cases.

switch(choice)
{

case 1:
{

//write your bubble sort logic here
break;
}

case 2:
{

//write your selection sort logic here
break;
}

case 3:
{

//write your insertion sort logic here
break;
}

}

Edited 5 Years Ago by harinath_2007: n/a

This article has been dead for over six months. Start a new discussion instead.