Friday 8 June 2012

 
class Subp
{
int a[],n,b[],j,i,t,p;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getData()throws IOException
{
System.out.println("enter the limit and enter the nos:");
n=Integer.parseInt(br.readLine());
a=new int[n];
for( i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}}

public void select()throws IOException
{
for(i=0;i<n;i++)
{
t=a[i];
p=i;

for(j=i+1;j<n;j++)
{
if(t>a[j])
{
t=a[j];
p=j;}
}
a[p]=a[i];
a[i]=t;
}
}
public void bubble()
{
for(i=0;i<n;i++)
{
for(j=0;j<n-2;j++)
{
if(a[j]>a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}}
}
}
public void insert()
{
for(i=1;i<n;i++)
{
int j=i;
int b=a[i];
while((j>0)&&(a[j-1]>b))
{
a[j]=a[j-1];
j--;
}
a[j]=b;
}}
public void pnt()throws IOException
{
for(i=0;i<n;i++)
{
System.out.print(a[i]);
}
}
}

class As
{

public static void main(String arg[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int s;
Subp t=new Subp();
t.getData();
System.out.println("select sorting 1->bubble  2->selection 3->insertion ");
 s=Integer.parseInt(br.readLine());
if(s==1)
{
t.bubble();
}
else if(s==2)
{
t.select();
}
else if(s==3)
{
t.insert();
}
t.pnt();
}
}

0 comments:

Post a Comment

Blogroll

Blogger templates

About