顯示具有 程式 標籤的文章。 顯示所有文章
顯示具有 程式 標籤的文章。 顯示所有文章

2009年3月4日 星期三

Quick Sort實作[JAVA版]


//*目的:使用者的輸入做Quick_Sort*/

//*安裝版本:J2SE 5.0 以上*/

//*方法一:Scanner*/

import java.util.Scanner;

//*註解為方法二:BufferedReader*/

//import java.io.BufferedReader;

//import java.io.InputStreamReader;

import java.io.IOException;

 

//*ex.排序方法

public class Quick_Sort{

    

    

    //*切割的點也就是取Pivot

    private static int partition(int a[],int left,int right){

        

         int i,j,temp,pivot;

        

        i=left+1;

        j=right;

        pivot=a[left];

        

        do{

            while(a[i]<pivot)i++;

            while(a[j]>pivot)j--;

            if(i<j){

                temp=a[i];

                a[i]=a[j];

                a[j]=temp;

            

            /* 可以做Bug的找碴~XD

            System.out.print("Begin\n");

            for(int k=0;k<a.length;k++){

            

                System.out.print(a[k] + " ");

            }

            System.out.print("end\n");

            */

            }

            

        }while(i<j);

        

        a[left]=a[j];

        a[j]=pivot;

        

        return j;

    }

    

    //*排序方法Quick Sort本體    

    private static void Main_Quick_Sort(int a[],int left,int right){

        

        int mid;

        

        if(left<right){

            

            //*用上個Method找Pivot

            mid = partition(a,left,right);

            

            //*邊換邊印給你看結果[*依分割次數]

            System.out.print("\n");

            for(int k=0;k<a.length;k++){

            

                System.out.print(a[k] + " | ");

            }

            System.out.print("\n");

            

            Main_Quick_Sort(a,left,mid-1);

            Main_Quick_Sort(a,mid+1,right);

            

        }else{

            

            //*我搞笑用~XD

            //System.out.print("@");

        }

        

    }

    

    //*主執行程式

    public static void main(String args[])throws IOException 

    {

    

        //*要存的陣列宣告a

        int b[] = new int[10];

        

        //*讀取輸入值

        //BufferedReader br=

         //    new BufferedReader(new InputStreamReader(System.in));

         Scanner scanner = new Scanner(System.in);

         

         System.out.print("1.計算輸入10個值的Quick Sort排序~\n"+

                                 "請輸入(都整數喔!!):");    

        for(int k=0;k<b.length;k++){

            

            b[k] = scanner.nextInt();

        }

        

        //*做銀幕的Check

        System.out.println("\n2.原本10個整數順序:");    

        for(int k=0;k<b.length;k++){

            

            System.out.print(b[k] + " | ");

        }

        System.out.println("\n\n3.轉換過程:");

        

        //**關鍵底枷啦!!要傳陣列給排序方法做

        Main_Quick_Sort(b, 0, b.length-1);

        

        System.out.println("\n4.排序後10個整數順序:");

        for(int k=0;k<b.length;k++){

            

            System.out.print(b[k] + " | ");

        }

        //*System.exit(0);

    }

    

}

2009年2月25日 星期三

<素材到>~Clock~!!

你想一些跟別人不一樣的flash時鐘嗎?

推薦幾個網站給你吧~

1.Design Flash Wall Gallery

他是一個日本網站,應該算是跟手機有關的,所以時鐘的畫面算是精巧路線

我隨便貼一個其中的:


反正有很多POP風的,很不錯~

2.Clocklink

應該不陌生吧~他是一個英文網站,光看名字就知是做時鐘的~XD

他比較有特色的是電子式,其他就是最中規中矩,很一般的~所以我不多做介紹囉:

3.Blog-pitatto

噹噹噹!!!這就是你現在看到我網頁的右下方水表提供者~XD

光看名字也知是專為部落格設計的,跟前2位不同是他沒提供Embed>標籤嵌入功能,所以有些拒絕使用JavaScript的部落就跟他無緣囉~

它提供不止時鐘,還有一些小遊戲...礙於技術方面,就暫時先不PO上來囉~

看呀~連那麼宅的"此方",用過都說 !!~XD