انا سويت برنامج جافا ع انواع البحث الي في مادة داتا استركشر واريد ميثود تطبع ناتج جميع انواع البحث
بحيث تكون دالة الطباعه خيار ضمن خيارات السويتش ويتم فيها طباعة ناتج البحث
كود:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Employee.mm;
/
*
* @author ibrahim
*/
import javax.swing.*;
public class sort {
public static void main(String[] ESA) {
String s1 =JOptionPane.showInputDialog("Enter the size of Array ");
int size=Integer.parseInt(s1);
int [] N_Student = new int [size] ;
for(int i = 0 ; i<N_Student.length ; i ++){
String s2 =JOptionPane.showInputDialog("Enter the value of Array ");
N_Student[i]=Integer.parseInt(s2);
}
while(true){
String s3 =JOptionPane.showInputDialog("Enter the Number of program\n 1- Bubble_Sort program\n 2-InsertionSort program \n 3-SelectionSort \n 4-Exit ");
int nu=Integer.parseInt(s3);
switch (nu){
case 1:
Bubble_Sort(N_Student);
break ;
case 2:
InsertionSort(N_Student);
break ;
case 3:
SelectionSort(N_Student);
break ;
case 4:
System.exit(0);
}}
}
public static void Bubble_Sort(int[]a)
{
int temp;
int n =a.length;
for(int j=0;j<=n;++j)
{
for(int i=0;i<n-1;++i)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
for(int i=0;i<n;i++){
System.out.print(a[i]+" " );
}
}
public static void InsertionSort(int[]a){
int i,k,x,j;
int n=a.length;
for(i=1;i<n;++i)
{
x=a[i];
j=i-1;
while (j>=0 && x<a[j])
{
a[j+1]=a[j];
j--;
}
a[j+1]=x;
}
for(int c=0;c<n;c++){
System.out.print(a[c]+ " " );
}
}
public static void SelectionSort(int list[]){
for (int b=0;b<list.length;b++){
System.out.print(list[b]+" ");}
System.out.println("");
System.out.println("Selection Sort");
int minIndex,temp;
for(int i=0;i<list.length;i++){
minIndex=i;
for (int j=i+1; j<list.length;j++)
if(list[j]<list[minIndex])
minIndex=j;
if(minIndex!=i){
temp=list[i];
list[i]=list[minIndex];
list[minIndex]=temp;
}
System.out.print(list[i]+" ");
}
}
}