⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arrays.java

📁 一份java写的期货交易程序
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   Arrays.java

package gnnt.MEBS.HQApplet;

import gnnt.MEBS.hq.ProductDataVO;
import java.io.PrintStream;

class Arrays
{

    Arrays()
    {
    }

    public static void sort(ProductDataVO a[], String strSortItem)
    {
        quickSort(a, 0, a.length - 1, strSortItem);
    }

    private static boolean lessThan(ProductDataVO one, ProductDataVO other, String strSortItem)
    {
        if(strSortItem.equals("Code"))
            return one.code.compareTo(other.code) < 0;
        if(strSortItem.equals("CurPrice"))
            return one.curPrice < other.curPrice;
        if(strSortItem.equals("TotalAmount"))
            return one.totalAmount < other.totalAmount;
        if(strSortItem.equals("UpValue"))
        {
            float oneUp = one.closePrice <= 0.0F || one.curPrice <= 0.0F ? 0.0F : one.curPrice - one.closePrice;
            float otherUp = other.closePrice <= 0.0F || other.curPrice <= 0.0F ? 0.0F : other.curPrice - other.closePrice;
            return oneUp < otherUp;
        }
        if(strSortItem.equals("UpRate"))
        {
            float oneUprate = one.closePrice != 0.0F ? ((one.curPrice - one.closePrice) / one.closePrice) * 100F : 0.0F;
            float otherUprate = other.closePrice != 0.0F ? ((other.curPrice - other.closePrice) / other.closePrice) * 100F : 0.0F;
            return oneUprate < otherUprate;
        }
        if(strSortItem.equals("TotalMoney"))
            return one.totalMoney < other.totalMoney;
        if(strSortItem.equals("AmountRate"))
            return one.amountRate < other.amountRate;
        if(strSortItem.equals("ConsignRate"))
            return one.consignRate < other.consignRate;
        else
            return true;
    }

    private static void quickSort(ProductDataVO a[], int left, int right, String strSortItem)
    {
        if(left < right)
        {
            ProductDataVO tmp = a[left];
            int i = left;
            for(int j = right; i < j;)
            {
                while(i < j && lessThan(a[j], tmp, strSortItem)) 
                    j--;
                if(i < j)
                    a[i++] = a[j];
                for(; i < j && !lessThan(a[i], tmp, strSortItem); i++);
                if(i < j)
                    a[j--] = a[i];
            }

            a[i] = tmp;
            quickSort(a, left, i - 1, strSortItem);
            quickSort(a, i + 1, right, strSortItem);
        }
    }

    private static void quickSort(int a[], int left, int right)
    {
        if(left < right)
        {
            int tmp = a[left];
            int i = left;
            for(int j = right; i < j;)
            {
                while(i < j && a[j] < tmp) 
                    j--;
                if(i < j)
                    a[i++] = a[j];
                for(; i < j && a[i] >= tmp; i++);
                if(i < j)
                    a[j--] = a[i];
            }

            a[i] = tmp;
            quickSort(a, left, i - 1);
            quickSort(a, i + 1, right);
        }
    }

    public static void main(String args[])
    {
        int a[] = {
            1, 2, 3, 4, 5
        };
        int b[] = {
            5, 4, 3, 2, 1
        };
        int c[] = {
            3, 2, 1, 4, 5
        };
        int d[] = {
            0x927c2, 0x927c1, 0x7a121
        };
        quickSort(a, 0, a.length - 1);
        quickSort(b, 0, b.length - 1);
        quickSort(c, 0, c.length - 1);
        System.out.println("before sort...");
        for(int i = 0; i < d.length; i++)
            System.out.print(d[i] + "\t");

        System.out.println("\n");
        quickSort(d, 0, d.length - 1);
        reverse(d);
        System.out.println("after sort...");
        for(int i = 0; i < d.length; i++)
            System.out.print(d[i] + "\t");

        System.out.println("\n");
    }

    static void reverse(int a[])
    {
        int size = a.length;
        int count = size / 2;
        for(int i = 0; i < count; i++)
        {
            int tmp = a[i];
            a[i] = a[size - i - 1];
            a[size - i - 1] = tmp;
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -