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

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

?? btreelfn.cpp

?? uc/os 很好的學習代碼
?? CPP
字號:
/*------------------------------------------------------------------------*/
/*                                                                        */
/*  BTREELFN.CPP                                                          */
/*                                                                        */
/*  Copyright Borland International 1991                                  */
/*  All Rights Reserved                                                   */
/*                                                                        */
/*------------------------------------------------------------------------*/

#if !defined( CHECKS_H )
#include <Checks.h>
#endif  // CHECKS_H

#if !defined( __BTREE_H )
#include <BTree.h>
#endif  // __BTREE_H

#ifndef __STDLIB_H
#include <stdlib.h>
#endif

#ifndef __IOSTREAM_H
#include <iostream.h>
#endif

//====== LeafNode functions =======

LeafNode::LeafNode(InnerNode* P, Sortable* O, Btree* T): Node(1, P, T)
{
    item = new Sortable *[maxIndex()+1];
    if( item == 0 )
        ClassLib_error( __ENOMEMLN );
    if( O != 0 )
        item[++last] = O;
}

LeafNode::~LeafNode()
{
    if( tree->ownsElements() )
        {
        for( int i = 0; i <= last; i++ )
            delete item[i];
        }
    delete [] item;
}

void LeafNode::add(Sortable *obj, int index)
{
    // add the object OBJ to the leaf node, inserting it at location INDEX
    // in the item array
    PRECONDITION( 0 <= index && index <= last+1 );
    PRECONDITION( last <= maxIndex() );
    for( int i = last+1; i > index ; i-- )
        item[i] = item[ i - 1 ];
    item[ index ] = obj;
    last++;

    // check for overflow
    if( parent == 0 )
        tree->incrNofKeys( );
    else
        parent->incrNofKeys( this );

    if( isFull() )
        {
        // it's full; tell parent node
        if( parent == 0 )
            {
            // this occurs when this leaf is the only node in the
            // btree, and this->tree->root == this
            CHECK( tree->root == this );
            // in which case we inform the btree, which can be
            // considered the parent of this node
            tree->rootIsFull();
            }
        else
            {
            // the parent is responsible for splitting/balancing subnodes
            parent->isFull( this );
            }
        }
}

void LeafNode::appendFrom( LeafNode* src, int start, int stop )
{
    // A convenience function, does not worry about the element in
    // the parent, simply moves elements from SRC[start] to SRC[stop]
    // into the current array.
    // This should never create a full node.
    // That is, it is not used anywhere where THIS could possibly be
    // near full.
    // Does NOT handle nofKeys.
    if( start > stop )
        return;
    PRECONDITION( 0 <= start && start <= src->last );
    PRECONDITION( 0 <= stop  && stop  <= src->last );
    PRECONDITION( last + stop - start + 1 < maxIndex() ); // full-node check
    for( int i = start; i <= stop; i++ )
        item[++last] = src->item[i];
    CHECK( last < maxIndex() );
}

void LeafNode::append( Sortable* D )
{
    // never called from anywhere where it might fill up THIS
    // does NOT handle nofKeys.
    item[++last] = D;
    CHECK( last < maxIndex() );
}


void LeafNode::balanceWithLeft( LeafNode* leftsib, int pidx )
{
    // THIS has more than LEFTSIB;  move some items from THIS to LEFTSIB.
    PRECONDITION( Vsize() >= leftsib->Psize() );
    int newThisSize = (Vsize() + leftsib->Psize())/2;
    int noFromThis  = Psize() - newThisSize;
    pushLeft( noFromThis, leftsib, pidx );
}

void LeafNode::balanceWithRight( LeafNode* rightsib, int pidx )
{
    // THIS has more than RIGHTSIB;  move some items from THIS to RIGHTSIB.
    PRECONDITION( Psize() >= rightsib->Vsize() );
    int newThisSize = (Psize() + rightsib->Vsize())/2;
    int noFromThis  = Psize() - newThisSize;
    pushRight( noFromThis, rightsib, pidx );
}

void LeafNode::balanceWith( LeafNode* rightsib, int pidx )
{
    // PITEM is the parent item whose key will change when keys are shifted
    // from one LeafNode to the other.
    if( Psize() < rightsib->Vsize() )
        rightsib->balanceWithLeft( this, pidx );
    else
        balanceWithRight( rightsib, pidx );
}

long LeafNode::findRank( Sortable* what ) const
{
    // WHAT was not in any inner node; it is either here, or it's
    // not in the tree
    for( int i = 0; i <= last; i++ )
        {
        if( *item[i] == *what )
            return i;
        if( *item[i] >= *what )
            return -1;
        }
    return -1;
}

LeafNode *LeafNode::firstLeafNode()
{
    return this;
}

Object& LeafNode::found(Sortable* what, Node** which, int* where )
{
    // WHAT was not in any inner node; it is either here, or it's
    // not in the tree
    for( int i = 0; i <= last; i++ )
        {
        if( *item[i] == *what )
            {
            *which = this;
            *where = i;
            return *item[i];
            }
        if( *item[i] >= *what )
            {
            *which = this;
            *where = i;
            return NOOBJECT;
            }
        }
    *which = this;
    *where = last+1;
    return NOOBJECT;
}

#pragma warn -rvl

int LeafNode::indexOf( const Sortable *that ) const
{
    // returns a number in the range 0 to maxIndex()
    for( int i = 0; i <= last; i++ )
        {
        if( item[i] == that )
            return i;
        }
    CHECK(0);
}

#pragma warn .rvl

LeafNode *LeafNode::lastLeafNode()
{
    return this;
}

void LeafNode::mergeWithRight( LeafNode* rightsib, int pidx )
{
    PRECONDITION( Psize() + rightsib->Vsize() < maxPsize() );
    rightsib->pushLeft( rightsib->Psize(), this, pidx );
    append( parent->getKey( pidx ) );
    parent->setNofKeys( pidx-1, nofKeys() );
    // cout << "in mergeWithRight:\n" << *parent << "\n";
    parent->removeItem( pidx );
    delete rightsib;
    // cout << "in mergeWithRight:\n" << *parent << "\n";
}

long LeafNode::nofKeys( int ) const
{
    return 1;
}

long LeafNode::nofKeys() const
{
    return Psize();
}

void LeafNode::printOn(ostream& out) const
{
    out << " < ";
    for( int i = 0; i <= last; i++ )
        out << *item[i] << " " ;
    out << "> ";
}

void LeafNode::pushLeft( int noFromThis, LeafNode* leftsib, int pidx )
{
    // noFromThis==1 => moves the parent item into the leftsib,
    // and the first item in this's array into the parent item
    PRECONDITION( noFromThis > 0 && noFromThis <= Psize() );
    PRECONDITION( noFromThis + leftsib->Psize() < maxPsize() );
    PRECONDITION( parent->getTree(pidx) == this );
    leftsib->append( parent->getKey(pidx) );
    if( noFromThis > 1 )
        leftsib->appendFrom( this, 0, noFromThis-2 );
    parent->setKey( pidx, item[noFromThis-1] );
    shiftLeft( noFromThis );
    parent->setNofKeys( pidx-1, leftsib->nofKeys() );
    parent->setNofKeys( pidx, nofKeys() );
}

void LeafNode::pushRight( int noFromThis, LeafNode* rightsib, int pidx )
{
    // noFromThis==1 => moves the parent item into the
    // rightsib, and the last item in this's array into the parent
    // item
    PRECONDITION(noFromThis > 0 && noFromThis <= Psize());
    PRECONDITION(noFromThis + rightsib->Psize() < maxPsize());
    PRECONDITION(parent->getTree(pidx) == rightsib);
    // The operation is five steps:
    //  Step I.  Make room for the incoming keys in RIGHTSIB.
    //  Step II. Move the key in the parent into RIGHTSIB.
    //  Step III.Move the items from THIS into RIGHTSIB.
    //  Step IV. Move the item from THIS into the parent.
    //  Step V.  Update the length of THIS.
    //
    // Step I.: make space for noFromThis items
    //
    int start = last - noFromThis + 1;
    int tgt, src;
    tgt = rightsib->last + noFromThis;
    src = rightsib->last;
    rightsib->last = tgt;
    while (src >= 0)
        rightsib->item[tgt--] = rightsib->item[src--];

    // Step II. Move the key from the parent into place
    rightsib->item[ tgt-- ] = parent->getKey( pidx );

    // Step III.Move the items from THIS into RIGHTSIB
    for( int i = last; i > start; i-- )
        rightsib->item[tgt--] = item[i];
    CHECK( tgt == -1 );

    // Step IV.
    parent->setKey( pidx, item[ start ] );

    // Step V.
    last -= noFromThis;

    // Step VI.  update nofKeys
    parent->setNofKeys( pidx-1, nofKeys() );
    parent->setNofKeys( pidx, rightsib->nofKeys() );
}

void LeafNode::remove( int index )
{
    PRECONDITION( index >= 0 && index <= last );
    for( int to = index; to < last; to++ )
        item[to] = item[to+1];
    last--;
    if( parent == 0 )
        tree->decrNofKeys();
    else
        parent->decrNofKeys( this );
    if( isLow() )
        {
        if( parent == 0 )
            {
            // then this is the root; when no keys left, inform the tree
            if( Psize() == 0 )
                tree->rootIsEmpty();
            }
        else
            parent->isLow( this );
        }
}

void LeafNode::shiftLeft( int cnt )
{
    if( cnt <= 0 )
        return;
    for( int i = cnt; i <= last; i++ )
        item[i-cnt] = item[i];
    last -= cnt;
}

void LeafNode::split()
{
    // this function is called only when THIS is the only descendent
    // of the root node, and THIS needs to be split.
    // assumes that idx of THIS in Parent is 0.
    LeafNode* newnode = new LeafNode( parent );
    CHECK( newnode != 0 );
    parent->append( item[last--], newnode );
    parent->setNofKeys( 0, parent->getTree(0)->nofKeys() );
    parent->setNofKeys( 1, parent->getTree(1)->nofKeys() );
    balanceWithRight( newnode, 1 );
}

void LeafNode::splitWith( LeafNode *rightsib, int keyidx )
{
    PRECONDITION(parent == rightsib->parent);
    PRECONDITION(keyidx > 0 && keyidx <= parent->last);
    int nofKeys        = Psize() + rightsib->Vsize();
    int newSizeThis    = nofKeys / 3;
    int newSizeNew     = (nofKeys - newSizeThis) / 2;
    int newSizeSib     = (nofKeys - newSizeThis - newSizeNew);
    int noFromThis     = Psize() - newSizeThis;
    int noFromSib      = rightsib->Vsize() - newSizeSib;
    CHECK(noFromThis >= 0);
    CHECK(noFromSib >= 1);
    LeafNode* newNode  = new LeafNode(parent);
    CHECK( newNode != 0 );
    parent->addElt( keyidx, item[last--], newNode );
    parent->setNofKeys( keyidx, 0 );
    parent->decNofKeys( keyidx-1 );
    this->pushRight( noFromThis-1, newNode, keyidx );
    rightsib->pushLeft( noFromSib, newNode, keyidx+1 );
    if( parent->isFull() )
        parent->informParent();
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本欧美一区二区在线观看| 欧美精品第1页| 欧美日韩免费观看一区三区| 欧美一区二区三区视频| 国产精品卡一卡二| 六月婷婷色综合| 在线视频一区二区三| 久久精品男人天堂av| 天堂一区二区在线| 色八戒一区二区三区| 国产欧美一区视频| 久久99久久99| 色天天综合色天天久久| 国产精品久久久久久一区二区三区 | jlzzjlzz亚洲日本少妇| 日韩欧美激情一区| 奇米综合一区二区三区精品视频| 成人在线视频一区| 久久久久久久电影| 韩国三级在线一区| 日韩欧美电影一区| 日本视频在线一区| 91 com成人网| 日韩精品一级二级| 欧美人体做爰大胆视频| 亚洲一区二区三区四区在线观看 | 亚洲乱码国产乱码精品精小说 | 亚洲va欧美va人人爽| 色94色欧美sute亚洲线路一久| 国产精品欧美久久久久一区二区 | 色天天综合久久久久综合片| 久久久不卡影院| 国产精品一二三在| 国产欧美一区二区精品忘忧草 | 欧美日韩午夜影院| 亚洲一区在线播放| 欧美日韩激情一区二区| 婷婷一区二区三区| 日韩一区二区在线观看视频 | 成人h动漫精品一区二区| 久久精品欧美一区二区三区不卡| 国产成人精品免费一区二区| 综合中文字幕亚洲| 色综合欧美在线视频区| 洋洋av久久久久久久一区| 欧洲国内综合视频| 日韩中文字幕1| 精品粉嫩超白一线天av| 国产电影精品久久禁18| 国产精品国产三级国产普通话蜜臀 | aaa亚洲精品一二三区| 综合欧美亚洲日本| 欧美亚洲一区二区在线| 三级欧美韩日大片在线看| 精品久久久久久无| 成人一级黄色片| 亚洲精品国产品国语在线app| 欧美午夜片在线看| 久久爱另类一区二区小说| 久久精品一区二区三区不卡牛牛| 成人性生交大片免费看在线播放| 国产精品国产三级国产aⅴ原创| 色哟哟欧美精品| 丝袜亚洲精品中文字幕一区| 精品女同一区二区| 国产成人精品亚洲777人妖 | 亚洲柠檬福利资源导航| 欧美日本精品一区二区三区| 久国产精品韩国三级视频| 国产精品久久久久国产精品日日| 欧美视频一区在线| 国产一区二区精品久久| 一区二区三区美女视频| 欧美精品一区二区不卡| 色婷婷亚洲精品| 免费美女久久99| 亚洲人成影院在线观看| 欧美成人性战久久| 欧美性色综合网| 福利电影一区二区| 日本亚洲电影天堂| 一区二区三区中文免费| 久久综合五月天婷婷伊人| 欧美亚洲图片小说| 成人精品视频一区二区三区 | 久久亚洲精品小早川怜子| 日本精品一级二级| 丁香一区二区三区| 久久91精品国产91久久小草| 亚洲综合免费观看高清完整版 | 国产精品久久久久久久第一福利 | 久久一区二区三区国产精品| 91国偷自产一区二区三区成为亚洲经典| 久久99久久久久久久久久久| 亚洲444eee在线观看| 亚洲欧洲韩国日本视频| 久久免费美女视频| 精品国产免费一区二区三区四区| 欧美欧美欧美欧美| 欧美无乱码久久久免费午夜一区| 91在线视频免费观看| av中文字幕不卡| 成人精品gif动图一区| 国产白丝网站精品污在线入口| 麻豆久久一区二区| 全部av―极品视觉盛宴亚洲| 亚洲国产精品天堂| 亚洲一级二级三级| 亚洲综合一二三区| 亚洲一线二线三线视频| 一区二区三区在线视频播放| ...xxx性欧美| 亚洲乱码国产乱码精品精小说| 亚洲欧洲精品一区二区三区不卡| 国产精品嫩草99a| 中文字幕av一区二区三区高| 日本一区二区三区四区在线视频| 国产亚洲综合性久久久影院| 国产亚洲综合色| 国产精品无码永久免费888| 国产网站一区二区| 国产精品女同一区二区三区| 亚洲视频精选在线| 亚洲猫色日本管| 亚洲午夜一区二区| 日本网站在线观看一区二区三区| 看电视剧不卡顿的网站| 久久国产视频网| 国产成人福利片| 色婷婷激情综合| 欧美日韩色一区| 日韩欧美自拍偷拍| 久久久噜噜噜久久中文字幕色伊伊| 国产视频一区二区在线| 亚洲欧美综合另类在线卡通| 一区二区三区高清不卡| 日韩国产欧美视频| 久久国产麻豆精品| 成年人午夜久久久| 欧美日本一区二区三区四区 | 国产成人自拍网| 一本久久综合亚洲鲁鲁五月天| 欧美日韩成人综合在线一区二区| 日韩欧美综合在线| 国产精品天美传媒| 亚洲综合色丁香婷婷六月图片| 麻豆国产欧美日韩综合精品二区| 国产一区二区不卡在线| 在线视频观看一区| 精品国产亚洲在线| 亚洲综合在线免费观看| 美女视频黄久久| 91视频com| 欧美v国产在线一区二区三区| 亚洲国产成人私人影院tom| 亚洲成人av福利| 国产精品乡下勾搭老头1| 在线国产电影不卡| 久久香蕉国产线看观看99| 一区二区三区在线视频免费| 国产精品综合二区| 欧美中文字幕一区二区三区亚洲| 精品国产污污免费网站入口| 亚洲综合色区另类av| 高清国产午夜精品久久久久久| 91精品中文字幕一区二区三区| 亚洲国产成人午夜在线一区| 麻豆视频观看网址久久| 欧美色综合网站| 中文字幕第一区第二区| 九九热在线视频观看这里只有精品| 成人18视频日本| 久久婷婷成人综合色| 日韩激情在线观看| 91色porny在线视频| wwww国产精品欧美| 日韩高清一级片| 91成人免费电影| 国产精品久久三| 国产高清久久久久| 日韩久久精品一区| 日韩经典中文字幕一区| 欧美性受xxxx黑人xyx性爽| 亚洲人成在线播放网站岛国 | 国产成人av一区| 日韩欧美成人激情| 天堂久久一区二区三区| 欧美日韩精品一区二区三区四区 | 久久99精品国产麻豆不卡| 欧美精品久久天天躁| 亚洲韩国精品一区| 欧美色综合天天久久综合精品| 亚洲欧美另类久久久精品| 99国产精品99久久久久久| 国产精品久久久久久久久久久免费看| 国产成人精品免费看| 国产精品美女一区二区| 国产成人精品免费在线| 国产精品五月天| 色偷偷成人一区二区三区91|