class ArrayDemo17
{
static void Shift(int x[])
{
int i,j,temp,count;
for(i=0;i<x.length;i++)
{
System.out.print(" "+x[i]+" ");
}
for(i=0;i<x.length;i++)
{
for(j=i;j<x.length;j++)
{
if(x[i]>x[j])
{
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
System.out.println("");
count=0;
for(i=0;i<x.length;i++)
{
if(x[i]<0)
count++;
}
for(i=count-1;i>=0;i--)
{
System.out.print(" "+x[i]+" ");
}
for(i=count;i<x.length;i++)
{
System.out.print(" "+x[i]+" ");
}
}
public static void main(String... S)
{
Shift(new int[]{1,12,3,4,5,6,7,5,10,-1,-3,0});
}
}
{
static void Shift(int x[])
{
int i,j,temp,count;
for(i=0;i<x.length;i++)
{
System.out.print(" "+x[i]+" ");
}
for(i=0;i<x.length;i++)
{
for(j=i;j<x.length;j++)
{
if(x[i]>x[j])
{
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
System.out.println("");
count=0;
for(i=0;i<x.length;i++)
{
if(x[i]<0)
count++;
}
for(i=count-1;i>=0;i--)
{
System.out.print(" "+x[i]+" ");
}
for(i=count;i<x.length;i++)
{
System.out.print(" "+x[i]+" ");
}
}
public static void main(String... S)
{
Shift(new int[]{1,12,3,4,5,6,7,5,10,-1,-3,0});
}
}
No comments:
Post a Comment