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

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

?? redblacktree.java

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

    // RedBlackTree class
    //
    // CONSTRUCTION: with a negative infinity sentinel
    //
    // ******************PUBLIC OPERATIONS*********************
    // void insert( x )       --> Insert x
    // void remove( x )       --> Remove x (unimplemented)
    // Comparable find( x )   --> Return item that matches x
    // Comparable findMin( )  --> Return smallest item
    // Comparable findMax( )  --> Return largest item
    // boolean isEmpty( )     --> Return true if empty; else false
    // void makeEmpty( )      --> Remove all items
    // void printTree( )      --> Print tree in sorted order

    /**
     * Implements a red-black tree.
     * Note that all "matching" is based on the compareTo method.
     * @author Mark Allen Weiss
     */
    public class RedBlackTree
    {
        /**
         * Construct the tree.
         * @param negInf a value less than or equal to all others.
         */
        public RedBlackTree( Comparable negInf )
        {
            header      = new RedBlackNode( negInf );
            header.left = header.right = nullNode;
        }

        /**
         * Insert into the tree. Does nothing if item already present.
         * @param item the item to insert.
         */
        public void insert( Comparable item )
        {
            current = parent = grand = header;
            nullNode.element = item;

            while( current.element.compareTo( item ) != 0 )
            {
                great = grand; grand = parent; parent = current;
                current = item.compareTo( current.element ) < 0 ?
                             current.left : current.right;

                    // Check if two red children; fix if so
                if( current.left.color == RED && current.right.color == RED )
                     handleReorient( item );
            }

                // Insertion fails if already present
            if( current != nullNode )
                return;
            current = new RedBlackNode( item, nullNode, nullNode );

                // Attach to parent
            if( item.compareTo( parent.element ) < 0 )
                parent.left = current;
            else
                parent.right = current;
            handleReorient( item );
        }

        /**
         * Remove from the tree.
         * Not implemented in this version.
         * @param x the item to remove.
         */
        public void remove( Comparable x )
        {
            System.out.println( "Remove is not implemented" );
        }

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

            RedBlackNode itr = header.right;

            while( itr.left != nullNode )
                itr = itr.left;

            return itr.element;
        }

        /**
         * Find the largest item in the tree.
         * @return the largest item or null if empty.
         */
        public Comparable findMax( )
        {
            if( isEmpty( ) )
                return null;

            RedBlackNode itr = header.right;

            while( itr.right != nullNode )
                itr = itr.right;

            return itr.element;
        }

        /**
         * Find an item in the tree.
         * @param x the item to search for.
         * @return the matching item or null if not found.
         */
        public Comparable find( Comparable x )
        {
            nullNode.element = x;
            current = header.right;

            for( ; ; )
            {
                if( x.compareTo( current.element ) < 0 )
                    current = current.left;
                else if( x.compareTo( current.element ) > 0 ) 
                    current = current.right;
                else if( current != nullNode )
                    return current.element;
                else
                    return null;
            }
        }

        /**
         * Make the tree logically empty.
         */
        public void makeEmpty( )
        {
            header.right = nullNode;
        }

        /**
         * Test if the tree is logically empty.
         * @return true if empty, false otherwise.
         */
        public boolean isEmpty( )
        {
            return header.right == nullNode;
        }

        /**
         * Print the tree contents in sorted order.
         */
        public void printTree( )
        {
            if( isEmpty( ) )
                System.out.println( "Empty tree" );
            else
                printTree( header.right );
        }

        /**
         * Internal method to print a subtree in sorted order.
         * @param t the node that roots the tree.
         */
        private void printTree( RedBlackNode t )
        {
            if( t != nullNode )
            {
                printTree( t.left );
                System.out.println( t.element );
                printTree( t.right );
            }
        }

        /**
         * Internal routine that is called during an insertion
         * if a node has two red children. Performs flip and rotations.
         * @param item the item being inserted.
         */
        private void handleReorient( Comparable item )
        {
                // Do the color flip
            current.color = RED;
            current.left.color = BLACK;
            current.right.color = BLACK;

            if( parent.color == RED )   // Have to rotate
            {
                grand.color = RED;
                if( ( item.compareTo( grand.element ) < 0 ) !=
                    ( item.compareTo( parent.element ) < 0 ) )
                    parent = rotate( item, grand );  // Start dbl rotate
                current = rotate( item, great );
                current.color = BLACK;
            }
            header.right.color = BLACK; // Make root black
        }

        /**
         * Internal routine that performs a single or double rotation.
         * Because the result is attached to the parent, there are four cases.
         * Called by handleReorient.
         * @param item the item in handleReorient.
         * @param parent the parent of the root of the rotated subtree.
         * @return the root of the rotated subtree.
         */
        private RedBlackNode rotate( Comparable item, RedBlackNode parent )
        {
            if( item.compareTo( parent.element ) < 0 )
                return parent.left = item.compareTo( parent.left.element ) < 0 ?
                    rotateWithLeftChild( parent.left )  :  // LL
                    rotateWithRightChild( parent.left ) ;  // LR
            else
                return parent.right = item.compareTo( parent.right.element ) < 0 ?
                    rotateWithLeftChild( parent.right ) :  // RL
                    rotateWithRightChild( parent.right );  // RR
        }

        /**
         * Rotate binary tree node with left child.
         */
        static RedBlackNode rotateWithLeftChild( RedBlackNode k2 )
        {
            RedBlackNode k1 = k2.left;
            k2.left = k1.right;
            k1.right = k2;
            return k1;
        }

        /**
         * Rotate binary tree node with right child.
         */
        static RedBlackNode rotateWithRightChild( RedBlackNode k1 )
        {
            RedBlackNode k2 = k1.right;
            k1.right = k2.left;
            k2.left = k1;
            return k2;
        }

        private RedBlackNode header;
        private static RedBlackNode nullNode;
            static         // Static initializer for nullNode
            {
                nullNode = new RedBlackNode( null );
                nullNode.left = nullNode.right = nullNode;
            }

        static final int BLACK = 1;    // Black must be 1
        static final int RED   = 0;

            // Used in insert routine and its helpers
        private static RedBlackNode current;
        private static RedBlackNode parent;
        private static RedBlackNode grand;
        private static RedBlackNode great;


            // Test program
        public static void main( String [ ] args )
        {
            RedBlackTree t = new RedBlackTree( new MyInteger( Integer.MIN_VALUE ) );
            final int NUMS = 40000;
            final int GAP  =   307;

            System.out.println( "Checking... (no more output means success)" );

            for( int i = GAP; i != 0; i = ( i + GAP ) % NUMS )
                t.insert( new MyInteger( i ) );

            if( NUMS < 40 )
                t.printTree( );
            if( ((MyInteger)(t.findMin( ))).intValue( ) != 1 ||
                ((MyInteger)(t.findMax( ))).intValue( ) != NUMS - 1 )
                System.out.println( "FindMin or FindMax error!" );

            for( int i = 1; i < NUMS; i++ )
                 if( ((MyInteger)(t.find( new MyInteger( i ) ))).intValue( ) != i )
                     System.out.println( "Find error1!" );
        }
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区成人在线视频 | 6080午夜不卡| aaa国产一区| 成人午夜激情视频| 国产精品亚洲第一| 国产很黄免费观看久久| 国产乱码精品一区二区三| 国内外成人在线视频| 美国十次综合导航| 国内成人精品2018免费看| 国产精品综合av一区二区国产馆| 青娱乐精品视频在线| 久久精品国产亚洲a| 久色婷婷小香蕉久久| 精品一区二区久久| 国产乱色国产精品免费视频| 岛国av在线一区| 不卡电影一区二区三区| 91猫先生在线| 欧美日韩国产乱码电影| 日韩欧美国产麻豆| 国产午夜亚洲精品不卡| 国产精品高清亚洲| 亚洲一区二区三区四区五区黄| 亚洲国产中文字幕| 久久福利视频一区二区| 国产精品一二三区在线| 在线中文字幕不卡| 欧美一级欧美一级在线播放| 欧美激情资源网| 亚洲在线视频网站| 久久99国内精品| 国产精品一级在线| 欧美日韩精品一区二区三区四区 | 日本va欧美va精品| 国产乱码一区二区三区| 在线观看免费一区| 26uuu成人网一区二区三区| 成人欧美一区二区三区1314| 天天av天天翘天天综合网 | 91在线观看美女| 制服丝袜国产精品| 国产精品国产精品国产专区不蜜| 亚洲va欧美va人人爽午夜| 成人免费视频播放| 色域天天综合网| 精品国产一二三区| 亚洲永久精品国产| 成人在线综合网站| 欧美一区二区播放| 一二三四社区欧美黄| 国产成人在线看| 91精品国产麻豆| 亚洲综合色噜噜狠狠| 成人性生交大片免费| 欧美大片在线观看| 亚洲成va人在线观看| 99久久精品费精品国产一区二区| 日韩精品一区二区三区老鸭窝| 亚洲精品一卡二卡| 成人app下载| 国产亚洲福利社区一区| 欧美aaa在线| 在线电影欧美成精品| 一区二区理论电影在线观看| 暴力调教一区二区三区| 精品99一区二区三区| 美女尤物国产一区| 日韩一级大片在线观看| 性欧美疯狂xxxxbbbb| 欧美日韩五月天| 亚洲高清视频中文字幕| 欧美色精品在线视频| 亚洲一区二区三区中文字幕| 色哟哟在线观看一区二区三区| 中文字幕av一区二区三区高| 国产乱码精品一区二区三区av| 精品国内二区三区| 狠狠久久亚洲欧美| 久久久久久久综合色一本| 韩国午夜理伦三级不卡影院| 欧美精品一区二区精品网| 麻豆成人免费电影| 日韩女优毛片在线| 久久99精品国产麻豆不卡| 精品乱人伦一区二区三区| 麻豆精品在线看| 久久综合九色综合欧美就去吻| 91婷婷韩国欧美一区二区| 中文字幕av不卡| 91在线一区二区| 亚洲成a人片在线观看中文| 欧美男女性生活在线直播观看| 偷拍亚洲欧洲综合| 欧美一二三区在线观看| 激情综合五月婷婷| 国产目拍亚洲精品99久久精品| eeuss鲁片一区二区三区| 亚洲午夜一区二区三区| 91精品视频网| 国产剧情一区在线| 亚洲一区视频在线观看视频| 欧美嫩在线观看| 国产精品一品二品| 亚洲男人的天堂在线观看| 欧美一区二区三区在线观看| 国产美女久久久久| 一级特黄大欧美久久久| 91精品国产欧美一区二区18| 国产高清在线观看免费不卡| 亚洲伦在线观看| 日韩免费电影一区| 91老师片黄在线观看| 蜜臀av一区二区在线观看| 国产精品免费视频观看| 欧美二区在线观看| 国产成人av电影在线| 亚洲午夜免费福利视频| 欧美精品一区二区三区蜜桃视频| av男人天堂一区| 免费成人在线播放| 亚洲精品国产精品乱码不99| 91精品国产aⅴ一区二区| 不卡一区在线观看| 美女高潮久久久| 亚洲综合久久久久| 久久久av毛片精品| 日韩精品中文字幕一区| 在线观看欧美精品| a级精品国产片在线观看| 麻豆国产91在线播放| 亚洲h在线观看| 亚洲色图欧美激情| 久久久精品国产免费观看同学| 欧美三级韩国三级日本一级| 懂色av中文一区二区三区| 久久99久久精品欧美| 亚洲宅男天堂在线观看无病毒| 国产三级精品在线| 亚洲精品在线免费播放| 欧美久久久影院| 欧美午夜一区二区三区免费大片| 成人久久久精品乱码一区二区三区| 蜜臀av国产精品久久久久| 亚洲第四色夜色| 一区二区三区蜜桃网| 亚洲同性同志一二三专区| 日本一二三不卡| 国产嫩草影院久久久久| 久久老女人爱爱| 欧美大黄免费观看| 日韩欧美国产电影| 欧美电影免费观看高清完整版在 | 亚洲在线一区二区三区| 亚洲欧洲在线观看av| 国产精品理伦片| 中文字幕一区二区三区在线播放 | 欧美一区二区视频网站| 欧美日韩日本视频| 欧美色涩在线第一页| 欧美羞羞免费网站| 欧美亚洲愉拍一区二区| 欧美亚洲日本国产| 欧美日韩久久不卡| 日韩欧美在线1卡| 精品日韩欧美在线| 久久精品网站免费观看| 日本一区二区三区四区在线视频| 久久久亚洲精品一区二区三区| 久久久久久久久99精品| 国产精品久久久一区麻豆最新章节| 中文字幕免费一区| 亚洲黄色性网站| 日韩精品成人一区二区三区| 青青草伊人久久| 国产激情精品久久久第一区二区 | 欧美日韩一区二区电影| 日韩片之四级片| 欧美韩日一区二区三区四区| 1区2区3区欧美| 日韩精品一二三四| 国产精品一区二区三区99| 91网上在线视频| 日韩一区二区电影网| 国产视频一区二区在线| 亚洲卡通欧美制服中文| 免费在线观看视频一区| 成人毛片老司机大片| 欧美视频第二页| 2023国产精品自拍| 一片黄亚洲嫩模| 久久国产尿小便嘘嘘| 91国在线观看| 久久女同性恋中文字幕| 亚洲一区在线视频观看| 国产黄色精品视频| 欧美日韩国产a| 亚洲欧洲日韩综合一区二区| 麻豆专区一区二区三区四区五区| 成人h版在线观看|