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

## Recommended Answers

Your question is not clear.
Specify what exactly you want to say..

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.

``````
``````

## All 6 Replies

Your question is not clear.
Specify what exactly you want to say..

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;
}
}
}
}
}``````

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;
}

}``````

If you dont know the code or logic of sorting technique , just google it and you'll find it..

txnz...... to all....:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.