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

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

?? rbtree.cpp

?? 我的紅黑樹的c++實現。主要特點是可以用dot工具把紅黑樹畫出來
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// file rbtree.cpp
//created by alpha 2008.11.3

#include "../headers/rbtree.h"
#include "../headers/dot.h"
#include "../headers/control.h"
#include <ctime>
#include <iostream>
#include <sstream>
#include <stack>

using namespace std;

// constructor of rbtree class
rbtree::rbtree ()
{
	NIL=new rbtnode;
	NIL->color = BLACK;
	NIL->key = -1;
	NIL->lchild = NULL;
	NIL->rchild = NULL;
	NIL->father = NIL;
	NIL->size = 0;
	root = NIL;
	num = 0;
}

//init rbtree
bool rbtree::init()
{
	cout<<"Please input the size of tree : ";
	srand((int)time(0));
	int size;
	cin>>size;
	for (int i=0; i!=size; i++){
		int swap = rand();
		insert (swap);
	}

	return true;
}
//visit the rbtree "t" in inOrder
void rbtree::inOrder()
{
	inOrder(root);
	return;
}
void rbtree::inOrder(rbtnode *node) 
{
    if ( node != NIL)
    {
        if ( NIL != node->lchild )
		{
			if (node->lchild->key > node->key)
			{
                cerr<<"inorder walk false!\n";
				exit(-1);
            }
            inOrder(node->lchild);
        }
        print(node);
        if ( NIL != node->rchild )
        {
            if (node->rchild->key < node->key)
            {
                cout<<"inorder walk false\n";
				exit(-1);
            }
            inOrder(node->rchild);
        }
    }
}
void rbtree::preOrder()
{
	preOrder(root,0,0);
	return;
}
void rbtree::preOrder(rbtnode *node, int level, int flag)
{
	int n = level;
	while(n)
	{
		cout<<"    ";
		n--;	
	}
	level++;
	if (NIL != node)
	{
		cout<<"("<<node->key;
		if(RED == node->color)
			cout<<"R,\n";
		else
			cout<<"B,\n";
	}
	else
	{
		cout<<"NIL";
		if(flag)
			cout<<")\n";
		else
			cout<<",\n";
	}
	if (NULL != node->lchild)
	{
		preOrder(node->lchild,level,0);
	}
	if (NULL != node->rchild && NIL == node->rchild)
	{
		preOrder(node->rchild,level,1);
	}
	else if(NULL != node->rchild)
		preOrder(node->rchild,level,0);
	n = level;
	if(NIL != node&&NIL != node->rchild)
	{
		n = level-1;
		while(n)
		{
			cout<<"    ";
			n--;	
		}
		cout<<")\n";
	}
	level--;
}
//find key in rbtree, return a rbtnode to rbtnode
rbtnode* rbtree::find(int key)
{
    rbtnode *x;
    // find the node
    x = root;
    do
    {
        if ( key == x->key )
            break;
        if (key < x->key)
        {
            if (NIL != x->lchild)
                x = x->lchild;
            else
			{
				cout<<"There is no "<<key<<" in the tree\n";
				return NULL;
			}
        }
        else
        {
            if (NIL != x->rchild)
                x = x->rchild;
            else
			{
				cout<<"There is no "<<key<<" in the tree\n";
				return NULL;
			}
        }
    } while (NIL != x);
    return x;
}

// print the rbtree
void rbtree::print(rbtnode *node)
{
	string color[2] = { "BLACK", "RED" };
	cout<<"Key="<<node->key<<"    color="<<color[node->color];
	if (NIL != node->father)
		cout<<"    father="<<node->father->key;
    if (NIL != node->lchild)
		cout<<"    left="<<node->lchild->key;
    if (NIL != node->rchild)
		cout<<"    right="<<node->rchild->key;
    cout<<endl;
}
void rbtree::print()
{
	preOrder();
}
// insert a key
bool rbtree::insert()
{
	cout<<"Please input the key of the rbtnode you want to insert : ";
	rbtnode *z = new rbtnode;
	cin>>z->key;
	rbtnode *y = NIL;
	rbtnode *x = root;
	if (x == NIL){
		root = z;
		z->father = NIL;
		z->lchild = NIL;
		z->rchild = NIL;
		z->color = BLACK;
	}
	else
	{
		while ( x != NIL ){
			y = x;
			if ( z->key < x->key )
				x = x->lchild;
			else
				x = x->rchild;
		}
		if ( z->key < y->key )
			y->lchild = z;
		else 
			y->rchild = z;
		z->father = y;
		z->lchild = NIL;
		z->rchild = NIL;
		z->color = RED;
		insertFixup (z);
	}
	if(NIL != z)
	{
		z->size = z->lchild->size + z->rchild->size + 1;
	}
	return true;
}
bool rbtree::insert(int initkey)
{
	rbtnode *z = new rbtnode;
	z->key = initkey;
	rbtnode *y = NIL;
	rbtnode *x = root;
	if (x == NIL){
		root = z;
		z->father = NIL;
		z->lchild = NIL;
		z->rchild = NIL;
		z->color = BLACK;
	}
	else
	{
		while ( x != NIL ){
			y = x;
			if ( z->key < x->key )
				x = x->lchild;
			else
				x = x->rchild;
		}

		if ( z->key < y->key )
			y->lchild = z;
		else 
			y->rchild = z;
		z->father = y;
		z->lchild = NIL;
		z->rchild = NIL;
		z->color = RED;
		insertFixup (z);
	}
	num++;
	if(NIL != z)
	{
		z->size = z->lchild->size + z->rchild->size + 1;
	}
	if(controlInsert)
	{
		stringstream snum;
		snum<<num;
		stringstream ss;
		ss<<initkey;
		string name = "step"+snum.str()+"_insertkey_" + ss.str();
		toJpg(name);
	}
	return true;
}
// rbtree fixup
void rbtree::insertFixup(rbtnode *z)
{
    rbtnode *y;
    while (root != z && RED == z->father->color)        
    {
        if (z->father == z->father->father->lchild)        
        {
            y = z->father->father->rchild;                        
            if (NIL != y && RED == y->color)                
            {
                z->father->color = BLACK;                        
                y->color = BLACK;                                        
                z->father->father->color = BLACK;                
                z = z->father->father;                                
            }
            else                                                                        
            {
                if (z == z->father->rchild)                        
                {
                    z = z->father;
                    leftRotate ( z );
                }
                z->father->color = BLACK;                        
                z->father->father->color = RED;                
                rightRotate(z->father->father);
            }
        }
        else                                                                                
        {
            y = z->father->father->lchild;                        
            if (NIL != y && RED == y->color)                
            {
                z->father->color = BLACK;                        
                y->color = BLACK;                                        
                z->father->father->color = RED;                
                z = z->father->father;                                
            }               
            else                                                                        
            {
                if (z == z->father->lchild)                        
                {
                    z = z->father;
                    rightRotate(z);
                }
                z->father->color = BLACK;                        
                z->father->father->color = RED;                
                leftRotate(z->father->father);
            }
        }
    } 
    root->color = BLACK;
}

// left rotate
void rbtree::leftRotate(rbtnode *A) 
{       
    rbtnode *B;
    B = A->rchild;

    A->rchild  = B->lchild;
    if (NIL != B->lchild)
        B->lchild->father = A;
    B->father = A->father;
    if ( A == root )
    {
        root = B;
    }
    else if ( A == A->father->lchild)
    {
        A->father->lchild = B;
    }
    else
    {
        A->father->rchild = B;
    }
    B->lchild = A;
    A->father = B;
}

//right rotate
void rbtree::rightRotate(rbtnode *A)
{
    rbtnode *B;
    B = A->lchild;

    A->lchild = B->rchild;
    if (NIL != B->rchild)
        B->rchild->father = A;

    B->father = A->father;
    if (A == root)
    {
        root = B;
    }
    else if (A == A->father->lchild)
    {
        A->father->lchild = B;
    }
    else
    {
        A->father->rchild = B;
    }
    A->father = B;
    B->rchild  = A;
}

bool rbtree::delNode(int key)
{
    rbtnode *x, *y, *z, *x_father;    
    z = find(key);                   // find key
    if (NIL == z)
	{
		cout<<"delrbtnode fault, there is no key "<<key<<endl;
		return false;
	}
    y = z, x = NIL, x_father = NIL; 
    if (NIL == y->lchild)
    {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲不卡av一区二区三区| 最新国产の精品合集bt伙计| 成人激情电影免费在线观看| 久久福利视频一区二区| 亚瑟在线精品视频| 亚洲国产精品一区二区www| 中文字幕亚洲一区二区av在线| 亚洲精品一区二区三区精华液| 日韩女优视频免费观看| 欧美综合欧美视频| 欧美色倩网站大全免费| 欧美色爱综合网| 欧美顶级少妇做爰| 欧美sm极限捆绑bd| 久久在线观看免费| 欧美激情一区二区三区全黄| 国产午夜久久久久| 成人欧美一区二区三区视频网页 | 一区二区三区免费看视频| 久久久久久久久久久久电影| 2023国产一二三区日本精品2022| 欧美精品一区二区不卡| 精品国产免费一区二区三区香蕉| 久久久91精品国产一区二区精品| 国产欧美一区二区三区沐欲| 中文字幕av在线一区二区三区| 国产精品乱码人人做人人爱| 18成人在线视频| 亚洲高清不卡在线| 精品中文字幕一区二区小辣椒| 国产精品中文字幕欧美| 91免费看`日韩一区二区| 欧美亚洲高清一区二区三区不卡| 在线播放一区二区三区| 精品国产成人系列| 亚洲精品videosex极品| 青娱乐精品视频在线| 国产91精品露脸国语对白| 色欧美日韩亚洲| 欧美不卡在线视频| 亚洲精品免费一二三区| 蜜桃视频一区二区三区在线观看| 成人禁用看黄a在线| 欧美日韩三级一区| 国产精品免费久久| 日韩国产高清影视| 99视频精品全部免费在线| 日韩一区二区三区精品视频| 国产精品天美传媒| 美女高潮久久久| 欧洲av一区二区嗯嗯嗯啊| 国产亚洲午夜高清国产拍精品| 亚洲精品成人少妇| 国产福利一区二区三区视频| 欧美视频在线不卡| 国产精品传媒入口麻豆| 精品一区二区国语对白| 欧美日韩高清不卡| 18成人在线观看| 国产美女一区二区三区| 日韩欧美www| 五月天激情综合| 在线精品亚洲一区二区不卡| 日本一区二区三区四区 | 亚洲国产aⅴ成人精品无吗| 国产精品一区三区| 日韩欧美不卡在线观看视频| 亚洲电影视频在线| 91色视频在线| 国产精品无人区| 国产精品77777| 精品奇米国产一区二区三区| 日本亚洲欧美天堂免费| 欧美三级资源在线| 一区二区三区欧美激情| 在线观看亚洲专区| 亚洲精品乱码久久久久久| 高清在线不卡av| 中文字幕国产一区| 国产成人在线免费观看| 久久九九久久九九| 国产福利91精品| 国产精品丝袜黑色高跟| 国产91精品露脸国语对白| 国产视频一区二区在线观看| 国产成人自拍在线| 欧美激情艳妇裸体舞| 不卡一区中文字幕| 亚洲色图在线视频| 在线视频欧美精品| 亚洲宅男天堂在线观看无病毒| 欧美在线观看视频一区二区| 午夜私人影院久久久久| 在线电影国产精品| 精品一区二区三区免费| 国产亚洲成aⅴ人片在线观看| 粉嫩av亚洲一区二区图片| 国产精品久久精品日日| 色综合视频在线观看| 亚洲一区在线观看网站| 91精品黄色片免费大全| 国内外精品视频| 国产精品久久久久三级| 日本韩国欧美一区| 免费精品99久久国产综合精品| 久久美女艺术照精彩视频福利播放| 国产九色精品成人porny| 中文字幕一区二区三区精华液 | 亚洲天堂成人在线观看| 欧美视频一区二| 精品一区二区三区视频| 亚洲欧洲日本在线| 91精品欧美福利在线观看| 国产成人亚洲精品青草天美| 亚洲三级电影全部在线观看高清| 在线成人高清不卡| 国产99久久精品| 亚洲电影视频在线| 国产日韩欧美精品一区| 在线免费一区三区| 国产精品原创巨作av| 亚洲制服丝袜av| 国产亚洲精品久| 精品视频色一区| 国产成人aaa| 免费在线观看一区二区三区| √…a在线天堂一区| 精品国产乱码久久| 91麻豆高清视频| 国产精品综合二区| 亚洲在线视频免费观看| 国产日韩欧美综合在线| 欧美一区二区三区人| 色综合久久88色综合天天6| 麻豆成人av在线| 亚洲电影欧美电影有声小说| 综合色中文字幕| 国产亚洲综合av| 欧美xfplay| 欧美一区二区三区日韩视频| 欧洲av一区二区嗯嗯嗯啊| av中文一区二区三区| 国产精品自在在线| 精品影院一区二区久久久| 日韩成人午夜精品| 亚洲影院在线观看| 亚洲人xxxx| 亚洲视频综合在线| 国产精品视频一区二区三区不卡| 精品不卡在线视频| 日韩视频一区二区三区 | 日韩高清欧美激情| 夜夜嗨av一区二区三区中文字幕| 国产精品理论片| 国产精品高清亚洲| 中文字幕精品在线不卡| 国产色婷婷亚洲99精品小说| 亚洲精品在线电影| www久久精品| 日本一区二区三区在线不卡| 欧美国产一区二区在线观看| 国产欧美日韩精品在线| 久久久99久久| 欧美国产丝袜视频| 国产精品乱码一区二区三区软件| 中文一区在线播放| 国产精品短视频| 一级日本不卡的影视| 亚洲一二三四区不卡| 午夜av一区二区| 裸体歌舞表演一区二区| 国产一区二区在线视频| 国产91精品一区二区麻豆亚洲| 成人动漫一区二区在线| 91麻豆国产福利精品| 欧美午夜理伦三级在线观看| 这里只有精品电影| 久久久久久久网| 亚洲天堂精品视频| 午夜视频一区二区三区| 久久成人免费网站| 国产麻豆午夜三级精品| youjizz国产精品| 欧美无乱码久久久免费午夜一区| 91精品福利在线一区二区三区| 欧美zozozo| 亚洲女厕所小便bbb| 日韩成人精品在线观看| 国产精品一区二区三区99| 色哟哟一区二区| 日韩欧美www| 久久亚洲私人国产精品va媚药| 国产精品久久看| 石原莉奈一区二区三区在线观看 | 欧美一区二区三区日韩视频| 国产欧美一区二区三区鸳鸯浴| 一区二区三区日韩在线观看| 美日韩一区二区| 91丝袜国产在线播放| 日韩精品一区二区在线|