package;
The public final class Demo {
/* is sorted by weight, output hat color
* For example: 5 mice, weight of 15 30 5 9 30, the color of the hat in turn cl_red, Cl_blue, Cl_blue, cl_y Ellow, Cl_gray,
* Then sort the output of the hat color sequence should be for Cl_blue, Cl_yellow, cl_red, Cl_blue, Cl_gray.
If there is no mouse, output null.
input Parameters: Mouse Array */
public
static mouse_color[] Sortmouse (mouse[] MOUSE)
{
if mouse==null| | MOUSE.LENGTH<=0) return null;
Mouse_color[] Result=new mouse_color[mouse.length];
Insert sort for
(int i=1;i<mouse.length;i++)
{
int J;
for (j=i-1;j>=0;j--)
if (mouse[j].weight<=mouse[i].weight) break
;
Mouse nowmouse=new Mouse (mouse[i].weight,mouse[i].color);
for (int k=i-1;k>j;k--)
{
mouse[k+1].weight=mouse[k].weight;
Mouse[k+1].color=mouse[k].color;
}
Mouse[j+1]=nowmouse;
}
for (int i=0;i<mouse.length;i++)
{
Result[i]=mouse[i].color
}
return result;
}