亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? binomialqueue.java

?? Data StructuresAnd Algorithm Analysis In Java Source Code
?? JAVA
字號:
    package DataStructures;

    // BinomialQueue class
    //
    // CONSTRUCTION: with a negative infinity sentinel
    //
    // ******************PUBLIC OPERATIONS*********************
    // void insert( x )       --> Insert x
    // Comparable deleteMin( )--> Return and remove smallest item
    // Comparable findMin( )  --> Return smallest item
    // boolean isEmpty( )     --> Return true if empty; else false
    // boolean isFull( )      --> Return true if full; else false
    // void makeEmpty( )      --> Remove all items
    // vod merge( rhs )       --> Absord rhs into this heap
    // ******************ERRORS********************************
    // Overflow if CAPACITY is exceeded

    /**
     * Implements a binomial queue.
     * Note that all "matching" is based on the compareTo method.
     * @author Mark Allen Weiss
     */
    public class BinomialQueue
    {
        /**
         * Construct the binomial queue.
         */
        public BinomialQueue( )
        {
            theTrees = new BinomialNode[ MAX_TREES ];
            makeEmpty( );
        }

        /**
         * Merge rhs into the priority queue.
         * rhs becomes empty. rhs must be different from this.
         * @param rhs the other binomial queue.
         * @exception Overflow if result exceeds capacity.
         */
        public void merge( BinomialQueue rhs ) throws Overflow
        {
            if( this == rhs )    // Avoid aliasing problems
                return;

            if( currentSize + rhs.currentSize > capacity( ) )
                throw new Overflow( );

            currentSize += rhs.currentSize;

            BinomialNode carry = null;
            for( int i = 0, j = 1; j <= currentSize; i++, j *= 2 )
            {
                BinomialNode t1 = theTrees[ i ];
                BinomialNode t2 = rhs.theTrees[ i ];

                int whichCase = t1 == null ? 0 : 1;
                whichCase += t2 == null ? 0 : 2;
                whichCase += carry == null ? 0 : 4;

                switch( whichCase )
                {
                  case 0: /* No trees */
                  case 1: /* Only this */
                    break;
                  case 2: /* Only rhs */
                    theTrees[ i ] = t2;
                    rhs.theTrees[ i ] = null;
                    break;
                  case 4: /* Only carry */
                    theTrees[ i ] = carry;
                    carry = null;
                    break;
                  case 3: /* this and rhs */
                    carry = combineTrees( t1, t2 );
                    theTrees[ i ] = rhs.theTrees[ i ] = null;
                    break;
                  case 5: /* this and carry */
                    carry = combineTrees( t1, carry );
                    theTrees[ i ] = null;
                    break;
                  case 6: /* rhs and carry */
                    carry = combineTrees( t2, carry );
                    rhs.theTrees[ i ] = null;
                    break;
                  case 7: /* All three */
                    theTrees[ i ] = carry;
                    carry = combineTrees( t1, t2 );
                    rhs.theTrees[ i ] = null;
                    break;
                }
            }

            for( int k = 0; k < rhs.theTrees.length; k++ )
                rhs.theTrees[ k ] = null;
            rhs.currentSize = 0;
        }        

        /**
         * Return the result of merging equal-sized t1 and t2.
         */
        private static BinomialNode combineTrees( BinomialNode t1,
                                                  BinomialNode t2 )
        {
            if( t1.element.compareTo( t2.element ) > 0 )
                return combineTrees( t2, t1 );
            t2.nextSibling = t1.leftChild;
            t1.leftChild = t2;
            return t1;
        }

        /**
         * Insert into the priority queue, maintaining heap order.
         * This implementation is not optimized for O(1) performance.
         * @param x the item to insert.
         * @exception Overflow if capacity exceeded.
         */
        public void insert( Comparable x ) throws Overflow
        {
            BinomialQueue oneItem = new BinomialQueue( );
            oneItem.currentSize = 1;
            oneItem.theTrees[ 0 ] = new BinomialNode( x );

            merge( oneItem );
        }

        /**
         * Find the smallest item in the priority queue.
         * @return the smallest item, or null, if empty.
         */
        public Comparable findMin( )
        {
            if( isEmpty( ) )
                return null;

            return theTrees[ findMinIndex( ) ].element;
        }

    
        /**
         * Find index of tree containing the smallest item in the priority queue.
         * The priority queue must not be empty.
         * @return the index of tree containing the smallest item.
         */
        private int findMinIndex( )
        {
            int i;
            int minIndex;

            for( i = 0; theTrees[ i ] == null; i++ )
                ;

            for( minIndex = i; i < theTrees.length; i++ )
                if( theTrees[ i ] != null &&
                    theTrees[ i ].element.compareTo( theTrees[ minIndex ].element ) < 0 )
                    minIndex = i;

            return minIndex;
        }

        /**
         * Remove the smallest item from the priority queue.
         * @return the smallest item, or null, if empty.
         */
        public Comparable deleteMin( )
        {
            if( isEmpty( ) )
                return null;

            int minIndex = findMinIndex( );
            Comparable minItem = theTrees[ minIndex ].element;

            BinomialNode deletedTree = theTrees[ minIndex ].leftChild;

            BinomialQueue deletedQueue = new BinomialQueue( );
            deletedQueue.currentSize = ( 1 << minIndex ) - 1;
            for( int j = minIndex - 1; j >= 0; j-- )
            {
                deletedQueue.theTrees[ j ] = deletedTree;
                deletedTree = deletedTree.nextSibling;
                deletedQueue.theTrees[ j ].nextSibling = null;
            }

            theTrees[ minIndex ] = null;
            currentSize -= deletedQueue.currentSize + 1;

            try
              { merge( deletedQueue ); }
            catch( Overflow e ) { }
            return minItem;
        }

        /**
         * Test if the priority queue is logically empty.
         * @return true if empty, false otherwise.
         */
        public boolean isEmpty( )
        {
            return currentSize == 0;
        }

        /**
         * Test if the priority queue is logically full.
         * @return true if full, false otherwise.
         */
        public boolean isFull( )
        {
            return currentSize == capacity( );
        }

        /**
         * Make the priority queue logically empty.
         */
        public void makeEmpty( )
        {
            currentSize = 0;
            for( int i = 0; i < theTrees.length; i++ )
                theTrees[ i ] = null;
        }


        private static final int MAX_TREES = 14;

        private int currentSize;            // # items in priority queue
        private BinomialNode [ ] theTrees;  // An array of tree roots
    

        /**
         * Return the capacity.
         */
        private int capacity( )
        {
            return ( 1 << theTrees.length ) - 1;
        }

        public static void main( String [ ] args )
        {
            int numItems = 10000;
            BinomialQueue h  = new BinomialQueue( );
            BinomialQueue h1 = new BinomialQueue( );
            int i = 37;

            System.out.println( "Starting check." );
            try
            {
                for( i = 37; i != 0; i = ( i + 37 ) % numItems )
                    if( i % 2 == 0 )
                        h1.insert( new MyInteger( i ) );
                    else
                        h.insert( new MyInteger( i ) );

                h.merge( h1 );
                for( i = 1; i < numItems; i++ )
                    if( ((MyInteger)( h.deleteMin( ) )).intValue( ) != i )
                        System.out.println( "Oops! " + i );
            }
            catch( Overflow e ) { System.out.println( "Unexpected overflow" ); } 
            System.out.println( "Check done." );
        }
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91女人视频在线观看| 一本色道久久加勒比精品 | 美女在线视频一区| 欧美一区2区视频在线观看| 日韩二区在线观看| 久久久久久亚洲综合| 福利一区二区在线| 亚洲小说欧美激情另类| 日韩一区二区麻豆国产| 国产精品自在欧美一区| 国产精品初高中害羞小美女文| 欧美日韩一区国产| 国产精品一品二品| 日韩国产在线一| 国产精品久久福利| 日韩一区二区三区在线| 在线日韩av片| 国产精品一区久久久久| 免费在线欧美视频| 午夜精品123| 国产精品高潮久久久久无| 久久影院午夜论| 欧美精品色一区二区三区| 99久精品国产| 亚洲一区二区三区四区中文字幕 | 国产精品麻豆久久久| 欧美日韩国产大片| 欧美日韩免费在线视频| 国产精品每日更新| www.亚洲免费av| 亚洲国产va精品久久久不卡综合| 亚洲综合网站在线观看| 亚洲国产精品久久久久秋霞影院| 亚洲成人福利片| 久久99日本精品| 国产69精品久久久久777| 99在线精品视频| 欧美剧情电影在线观看完整版免费励志电影| 91同城在线观看| 欧美久久一二区| 91精品国产综合久久久久久 | 激情综合色综合久久| 日韩精品免费专区| 午夜电影网一区| 亚洲国产精品一区二区尤物区| 亚洲va欧美va天堂v国产综合| 亚洲高清免费视频| 久久er精品视频| 国产a区久久久| 欧美一区二区三区四区在线观看| 欧美一区午夜视频在线观看| 国产日韩欧美制服另类| 久久久久99精品国产片| 亚洲免费av高清| 午夜精品国产更新| 国产成人av电影在线观看| 色综合久久久久久久久久久| 欧美日韩国产成人在线91| 欧美激情一区二区三区不卡 | 成人高清视频在线观看| 有码一区二区三区| 久久精品亚洲精品国产欧美| 国产精品灌醉下药二区| 日本vs亚洲vs韩国一区三区| 欧美sm美女调教| 欧美色图片你懂的| 亚洲一区二三区| 国产精品99久久久久| 欧美亚日韩国产aⅴ精品中极品| 精品国产乱码久久| 亚洲一区二区在线免费看| 国产成人一区二区精品非洲| 在线不卡一区二区| 亚洲欧美日韩系列| 91一区在线观看| 欧美一区二区三区视频在线| 亚洲人成伊人成综合网小说| 国产suv一区二区三区88区| 欧美日韩综合在线| 亚洲精品国产无套在线观| 国产mv日韩mv欧美| 日韩三区在线观看| 亚洲第一福利视频在线| 北条麻妃国产九九精品视频| 精品国产乱码久久久久久久| 亚洲va欧美va人人爽| 色婷婷综合久久久中文一区二区 | 中文在线免费一区三区高中清不卡| 亚洲一区欧美一区| 欧美三级韩国三级日本三斤| 一区二区成人在线视频| 97国产一区二区| 亚洲欧美精品午睡沙发| 欧美怡红院视频| 亚洲成人tv网| 欧美日韩一区二区三区视频| 免费在线看成人av| 日本福利一区二区| 国产亚洲一本大道中文在线| 亚洲gay无套男同| 色综合久久66| 亚洲va韩国va欧美va| 欧美日韩专区在线| 欧美日韩国产综合久久| 日韩视频123| 免费人成精品欧美精品| 欧美亚洲禁片免费| 一区二区三区不卡在线观看| 色综合一区二区| 日韩美女视频一区| 97精品国产97久久久久久久久久久久| 国产精品女主播av| 成人av在线电影| 成人欧美一区二区三区在线播放| 国产亚洲成aⅴ人片在线观看 | 一区二区欧美国产| 精品国产一区二区亚洲人成毛片| 国产精品亚洲专一区二区三区| 国产精品卡一卡二| 在线观看一区二区精品视频| 日本91福利区| 亚洲精品成人悠悠色影视| 日韩小视频在线观看专区| 波多野结衣欧美| 免费人成精品欧美精品| 综合激情网...| 欧美v日韩v国产v| 在线播放91灌醉迷j高跟美女 | 国产精品久久久99| 欧美三级日韩在线| 亚洲一区电影777| 国产精品福利一区二区| 精品福利一区二区三区免费视频| 91蜜桃免费观看视频| 男女性色大片免费观看一区二区 | 国产91在线观看| av中文字幕不卡| 久久久久久亚洲综合| 婷婷综合另类小说色区| 成人黄色国产精品网站大全在线免费观看 | 久久精品夜夜夜夜久久| 国产高清在线观看免费不卡| **欧美大码日韩| 欧美精品99久久久**| 国产一区在线不卡| 精品sm在线观看| 久久久久国产精品厨房| 精品国产一区二区三区四区四| 欧美人伦禁忌dvd放荡欲情| 欧美日韩一区二区在线视频| 色综合久久久久网| 日本韩国欧美三级| 欧美图区在线视频| 91精品欧美综合在线观看最新 | 久99久精品视频免费观看| 亚洲成人三级小说| 婷婷丁香久久五月婷婷| 日韩在线卡一卡二| 激情六月婷婷久久| 91在线你懂得| 欧美丰满嫩嫩电影| 日韩午夜av一区| 亚洲国产精品av| 亚洲3atv精品一区二区三区| 首页综合国产亚洲丝袜| 美国十次综合导航| 国产69精品久久久久毛片| 91国偷自产一区二区开放时间 | 成人免费看的视频| 日本道色综合久久| 久久天堂av综合合色蜜桃网| 九九在线精品视频| 在线观看日韩国产| 欧美一区2区视频在线观看| 色呦呦国产精品| 欧美福利视频一区| 亚洲欧美自拍偷拍色图| 亚洲国产成人av好男人在线观看| 在线成人小视频| 欧美性生活一区| 午夜视频一区在线观看| 欧美日韩激情在线| 99视频在线精品| 国产精品亚洲视频| 日本视频中文字幕一区二区三区| 亚洲人123区| 国产蜜臀av在线一区二区三区| 欧美一三区三区四区免费在线看| 成人av中文字幕| 国产一区二区三区蝌蚪| 日韩高清欧美激情| 欧美日韩aaa| 亚洲自拍偷拍欧美| va亚洲va日韩不卡在线观看| 久久一夜天堂av一区二区三区| 亚洲成av人片在线观看无码| 91原创在线视频| 中文字幕在线观看一区| 国产一区二区伦理| 337p粉嫩大胆色噜噜噜噜亚洲|