冒泡排序

上一篇 / 下一篇  2012-05-26 22:45:51 / 个人分类:java

package xiti;
import java.applet.*;
import java.util.Random;
 class ti2 extends Applet {
  ti2()
  {
   int t;
   Bubble test= new Bubble(10);
   test.inserNum(1);
   test.inserNum(0);
   test.inserNum(9);
   test.inserNum(-1);
   test.inserNum(100);
   test.inserNum(3);


   test.dispaly();
   test.order();
   test.dispaly();
  
  
  }

}
class Bubble{
 int[] nums;
 int no;
 Bubble(int len)
 {
  nums=new int[len];
  no=0;
 }
 
 void inserNum(int value)
 {
  nums[no]=value;
  no++;
 }
 
 void order()
 {
  int temp;
  for(int i=0; i<no; i++)
  {
   for(int j=0;j<no-i-1;j++)
   {
    if(nums[j]>nums[j+1])
    {
     temp=nums[j+1];
     nums[j+1]=nums[j];
     nums[j]=temp;
   
    }
   }
  }
 }
 
 void dispaly()
 {
  for(int i=0;i<no;i++)
  {
   System.out.println(nums[i]+"-----");
  }
 }
 
 void delete(int value)
 {
  order();
  for(int i=0;i<no;i++)
  {
   if(nums[i]==value)
   {System.out.print("find value");
      for(int j=i;j<no;j++)
      {
       nums[j]=nums[j+i];
      
      }
      no--;
   }
  }
  
 }
}


TAG:

 

评分:0

我来说两句

Open Toolbar