Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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;
}
}


Ïà¹ØÎĵµ£º

ÔõÑù²é¿´Jsp±àÒëºóÉú³ÉµÄJavaÎļþ

      ¿ÉÄÜ´ó¶àÊýJsp¿ª·¢Ô±ÔÚдÍê³ÌÐò²âÊÔͨ¹ýºó£¬²»Ì«»á¹Ø×¢JspÉú³ÉµÄJavaÎļþ£¬Æäʵ£¬Í¨¹ýJava´úÂ룬¸üÄÜÌåÏÖ³ÌÐò´úÂëµÄÕæÕýº¬Ò壬¶Ô½øÒ»²½Ñо¿³ÌÐò´úÂëµÄºǫ́ÔËÐÐÇé¿öÊǷdz£ÓаïÖúµÄ¡£ÀýÈ磬ÓÃJsp±àд´úÂëʱ£¬ÓÐʱºòÓÃ<%!   %>£¬ÓÐʱºòÓÃ<%   %>£¬¼Ó²»¼Ó¸Ð̾º ......

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

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

java GBת UTF 8×Ö·û

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class GB2UTF
{
 public static String GBK2Unicode(String str)
 {
  StringBuffer result = new StringBuffer();
  for (int i = 0; i < str.length(); i++)
 &n ......

javaʵÏÖµÄÑ¡ÔñÅÅÐò

ÏÂÃæÊÇÓÃjavaʵÏÖµÄÑ¡ÔñÅÅÐò£¬Ã¿´Î´ÓÊý×éÖÐÑ¡È¡×îСµÄÖµ£º
import java.util.Date;
import java.util.Random;
/*
* Ñ¡ÔñÅÅÐò
*/
public class SelectSort {
public static void main(String args[])
{
int len = 40;
Date date = new Date();
Random random = new Random(date.getSeconds());
int ......

javaʵÏֵĹ鲢ÅÅÐò

Ò»ÏÂÊÇjavaʵÏÖµÄÓÐÒ»¸ö¹é²¢ÅÅÐò£¬×Ô¼º·¢ÏÖ×Ô¼ºµÄ»ù´¡¹¦Ì«²îÁË£¬ËùÒÔ×î½ü¿ªÊ¼Ñ§Ï°Ëã·¨£¬ºÃºÃµÄÁªÏµÃ¿Ò»Ëã·¨£¬¸÷λ´óÉñ²»Òª¼ûЦ£¬Ð´µÄÓдíµÄµØ·½Ï£ÍûÄܹ»Ö¸³öÀ´Ð»Ð»¹þ£º
package sort;
import java.util.Date;
import java.util.Random;
/*
* ¹é²¢ÅÅÐò
*/
public class MergeSort {
public static void main(Stri ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ