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

📄 test2.cpp

📁 CMXBTree 的主要作用是在内存中建立一棵B+树
💻 CPP
字号:
#include "cmxstring.h"
#include "cmxbtree.h"
#include <strstrea.h>
void test( CMXString str )
{
    return ;
}
typedef CMXBTree<CMXString> StringTree;
typedef CMXBTree<int> IntTree;

void main_bak2 (void)
{

    //先定义一棵树,元素类型是:CMXString
    //注:CMXString 是我定义的一个专门处理字符串的类
    //    它支持 小于操作符(<) 和 赋值操作符(=)
    CMXBTree<CMXString> bt;
    CMXString str3;
    //ostrstream myString;
    printf("[%d][%d][%d]\n", sizeof( ostrstream ), sizeof(str3), sizeof(bt) );
    long lLong = 123;
    double dDouble=123.5;
    str3 << 'a'<<'b'<<lLong<<dDouble;
    printf("%s\n", str3);
    
    test( str3 );

    //定义需要的变量及指针
    CMXString str2, str, *pStr, *pStr1, *pStr2;
    str2 = NULL;
    printf("%d\n", str2.Length() );

    str2 << str3;

    //这是局向
    char* pszStr = "8517 8519  8610 8611 8615 8620 8625 8630 8635 "
                    "8640 8645 8650 8655 8660 8665 8540 8541 8542 "
                    "8670 8672 8675 8677 8682 8684 8686 8621 "
                    "8690 8691 8692 8693 8694 8697 85186 1中文2 可以 123这是局向 ";
    char* pszStr2 = " 8517 8677 8693  8693 ";

//    while( true )
    {
        str = pszStr2;
        str2 = str.GetFirstToken(" "); //以空格为分隔符,把 pszStr 一个个地切开
        while( !str2.IsEmpty() )  //如果还没有到字符串的末尾
        {
            if( str2.Length() > 0 ) //如果两个空格间有东西,
                bt.InsertKey( str2 ); //把 str2 插入
            str2 = str.GetNextToken( ); //取下一个局向
        }   
   }
    str = "abc";
    int k  =1;
    printf("Count[%d]\n", bt.GetCount() );
    //bt.DestroyTree();
    printf("Count[%d]\n", bt.GetCount() );

    //来到这里表示树已建成
    //接下来,我们把树的所有元素按照从小到大的顺序排列出来
    CMXBTree<CMXString>::GET_KEY gk;

   
    pStr = bt.GetFirstKey(&gk);

    k = 0;
    while( pStr )
    {
        printf("[%s]", *pStr );
        k++;
        pStr = bt.GetNextKey(&gk);
    }

    printf("k=[%d]\n", k);
    
    //看看字符串 "85186" 是否存在
    str2 = "1中文2";
    pStr = bt.SearchKey( str2, NULL, &pStr1, &pStr2 );
    if( pStr )
        printf("[%s] is in the tree\n", str2 );
    else
        printf("Cannot find [%s]\n", str2 );

    //看看电话号码 8677123 是否在这个局中
    
    str2 = "8518612";
    pStr = bt.SearchKey( str2,NULL, &pStr1, &pStr2 );
    if( pStr1 ) 
    {
        if( str2.FindFirst( (*pStr1).C_str() ) == str2.C_str() ) //*pStr1 应该就是 8677
            printf("Yes!\n");
    }

    //如果 pStr1 为 NULL ,表示 str2 比所有的局向数据小,
    //则表示 str2 一定不在局向内
    
    

/*    CMXBTree<CMXString> bt;
    CMXString str2, str, *pStr, *pStr1, *pStr2, str3;

    char* pszStr = " 12 8517 8519  8610 8611 8615 8620 8625 8630 8635 "
                    "8640 8645 8650 8655 8660 8665 8540 8541 8542 "
                    "8670 8672 8675 8677 8682 8684 8686 8621 "
                    "8690 8691 8692 8693 8694 8697 85186";
    str = pszStr;
    str3 = "HuiZhanCC08";
    str << " " << str3;
    str2 = str.GetFirstToken(" ");
    while( !str2.IsEmpty() )
    {
        if( str2.Length() > 0 )
            bt.InsertKey( str2 );
        str2 = str.GetNextToken( );
    }   
    
    
    pStr = bt.SearchKey( str2, &pStr1, &pStr2 );
    bt.DeleteKey( str2 );
    pStr = bt.SearchKey( str2, &pStr1, &pStr2 );

    str2 = "12345";
    pStr = bt.SearchKey( str2, &pStr1, &pStr2 );

    if( (*pStr1).IsDigit() )
        printf("All digit\n");

    if( pStr1 && str2.FindFirst( *pStr1 ) == str2 )
        printf("Yes!\n");
    pStr = bt.GetFirstKey();
    while( pStr )
    {
        printf("[%s]", pStr->C_str() );
        pStr = bt.GetNextKey();
    }
*/
}

⌨️ 快捷键说明

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