0% found this document useful (0 votes)
12 views2 pages

Java Array Sorting Techniques

Uploaded by

harshdada310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Java Array Sorting Techniques

Uploaded by

harshdada310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

simport [Link].

*;
public class ArraySort {
int[] arr = new int[10];
public void getData() {
int i;
Scanner sc= new Scanner([Link]);
[Link](" Enter the elements ");
for(i=0;i<=9;i++) {
arr[i]=[Link]();
}
}
public void display() {
[Link](" Elements of array are ");
for(int i=0;i<=9;i++) {
[Link](arr[i]);
}
}
public void bSort() {
int i,j,temp;
for(i=0;i<=8;i++) {
for(j=0;j<=9;j++) {
if(arr[i]>=arr[j]) {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;

}
}
}

}
public void bubbleSort() {
int i,j,temp;
for(i=0;i<=8;i++) {
for(j=0;j<=9;j++) {
if(arr[i]>arr[i+1]) {
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}

}
public void shell() {
int gap=10/2;
int i,k,temp;
while(gap>=1)
{
for(i=0;i<=9-gap;i++)
{
if(arr[i]>arr[i+gap])
{
temp=arr[i];
arr[i]=arr[i+gap];
arr[i+gap]=temp;
}

}
gap=gap/2;
}

gap=1;
for(k=0;k<=4;k++)
{
for(i=0;i<=9-gap;i++)
{
if(arr[i]>=arr[i+gap])
{
temp=arr[i];
arr[i]=arr[i+gap];
arr[i+gap]=temp;
}
}
}
}

public static void main(String[] args) {


// TODO Auto-generated method stub
ArraySort obj1 = new ArraySort();
[Link]();
//[Link]();
//[Link]();
//[Link]();
[Link]();
[Link]();

You might also like