Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javaʵÏֵĵݹ鷽·¨ÄæÐò¶Ô²éÕÒ

ÏÂÃæÊÇʹÓÃjavaʵÏֵĵݹéÄæÐò¶Ô²éÕÒ£¬ËùνµÄÄæÐò¶Ô¾ÍÊÇÔÚÊý×éA[]ÖÐÈç¹û i < j ,²¢ÇÒA[i] > A[j], ÔòÎÒÃÇ˵A[i]ºÍA[j]ÊÇÒ»¶ÔÄæÐò¶Ô¡£Èç¹ûÓÃÆÕͨµÄË㷨ʵÏֵĻ°£¬²éÕÒµÄʱ¼ä¸´ÔӶȣ¬ÊÇO(N*N)£¬Ê¹ÓÃÕâÀïµÄ¶Ó¹æµÄ·½Ê½²éÕҵĻ°£¬Ê±¼ä¸´ÔÓ¶ÈÊÇO(N*lgN)
import java.util.Date;
import java.util.Random;
/*
* ʹÓõݹéʵÏÖµÄͳ¼ÆÊý×éÖеÄÄæÐò¶ÔÊýÁ¿¡£
*/
public class InversionSearch {

public static void main(String args[])
{
int len = 5;
Date date = new Date();
Random random = new Random(date.getSeconds());
int data[]=new int[len];
for(int i = 0; i < len; i++)
{
data[i]=(int)(random.nextFloat()*100+1);
}
show(data);
int count= inversionSearch(data,1,data.length);
System.out.println("¹²ÓÐÄæÐò¶Ô£º"+count);
}
private static void show(int[] data)
{
System.out.println("========================");
for(int i = 0; i < data.length; i++)
{
System.out.print(data[i] + " ");
}
System.out.println();
System.out.println("========================");
}

public static int inversionSearch(int[] data,int start,int end)
{
int count=0;
if(end>start){
int pos = (start+end)/2;
int temp1 = inversionSearch(data,start,pos);
int temp2 = inversionSearch(data,pos+1,end);
count = mergeSearch( data,start,pos,end)+temp1+temp2;
}
return count;
}

public static int mergeSearch(int[] data,int start,int pos,int end)
{
int count=0;
for(int i=pos; i<end; i++)
{
for(int j=start-1; j<pos; j++)
{
if(data[i]<data[j])
{
count++;
}
}
}
return count;
}
}


Ïà¹ØÎĵµ£º

Java NIO APIÏê½â

 
Java NIO APIÏê½â
ÔÚJDK
1.4ÒÔÇ°£¬JavaµÄIO²Ù×÷¼¯ÖÐÔÚjava.ioÕâ¸ö°üÖУ¬ÊÇ»ùÓÚÁ÷µÄ×èÈû£¨blocking£©API¡£¶ÔÓÚ´ó¶àÊýÓ¦ÓÃÀ´Ëµ£¬ÕâÑùµÄAPIʹÓúܷ½
±ã£¬È»¶ø£¬Ò»Ð©¶ÔÐÔÄÜÒªÇó½Ï¸ßµÄÓ¦Óã¬ÓÈÆäÊÇ·þÎñ¶ËÓ¦Óã¬ÍùÍùÐèÒªÒ»¸ö¸üΪÓÐЧµÄ·½Ê½À´´¦ÀíIO¡£´ÓJDK 1.4Æð£¬NIO
API×÷Ϊһ¸ö»ùÓÚ»º³åÇø£¬²¢ÄÜÌṩ·Ç×èÈû(non-blo ......

Java SE Òì³£

package demo;
class TestA{
 public int devide(int x,int y) throws ArithmeticException , DevideByMinusException{
  if(y<0)
   throw new DevideByMinusException("±»³ýÊýΪ¸º",y);
  int result=x/y;
  return result;
 }
}
public class TestE ......

JavaÖÐʹÓÃBigDecimalʵÏÖ¾«È·ÉáÎåÈë¼°¹¤³ÌÔËËã

£¨×¢£ºÇ°ÃæдÁËÒ»¸ö³¬´óÕûÊýÏà¼ÓµÄÀ࣬²Î¼û£º ³¬´óÕûÊýÏà¼Ó£¬³¬¹ýÁËlongµÄ·¶Î§£¬ÄãÒªÔõô×ö£¡£¬ºóÀ´ÓÐÅóÓÑÆÀÂÛ˵BigDecimal¿ÉÒÔÍêȫʵÏÖÎÒµÄÕâÕâ¸ö¹¦ÄÜ£¬¸Õ¿ªÊ¼µÄʱºò£¬ÎÒ»¹²»·þÆø£¬¾ÝÎÒËùÖªÄÇÀïÓÐÕâÑùµÄÀàŶ£¬ºóÀ´±¨×Å˵·þËûµÄÐÄÀíÈ¥ÕÒÁËһϣ¬ºÇºÇ£¬½á¹û¾ÓÈ»×Ô¼º±»Ëµ·þÁË£¬È·ÊµÓÐÕâôһ»ØÊ£¬ÀûÓÃBigDecimal²Ù×÷³¬´óÕûÊýÒ ......

win7£¨windows7£©ÏÂjava»·¾³±äÁ¿ÅäÖ÷½·¨

win7£¨windows7£©ÏÂjava»·¾³±äÁ¿ÅäÖ÷½·¨
 
 
windows7ÏÂjava»·¾³±äÁ¿ÅäÖ÷½·¨£º
   1.ÓÃÊó±êÓÒ»÷“ÎҵĵçÄÔ”->ÊôÐÔ  
  
   Ñ¡Ôñ×ó±ßµ¼º½µÄ“¸ß¼¶ÏµÍ³ÉèÖÔѡÏȻºóÕâ»ØÊìϤÁË°É£¿
  
   ¼ÌÐøÑ¡ÔñÓÒϽǵÄ& ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ