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

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

?? trees.cpp

?? 對三種數據結構的分析.avl tree,splaytree和binary search tree的插入和刪除的算法復雜度分析.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
	else if(element < T->Element) /* element is smaller than the T->Element */
	{
		T->Left=A_Insert(element,T->Left); /* go to the left subtree */
		if(Height(T->Left) - Height(T->Right)==2) /* unbalance */
			if(element < T->Left->Element) /* LL rotation */
				T=A_SingleRotateWithLeft(T);
			else /* LR ratation */
				T=A_DoubleRotateWithLeft(T);
	}
	else if(element > T->Element) /* element is larger than the T->Element */
	{
		T->Right=A_Insert(element,T->Right); /* go to the right subtree */
		if(Height(T->Right) - Height(T->Left)==2) /* unbalance */
			if(element > T->Right->Element) /* RR rotation */
				T=A_SingleRotateWithRight(T);
			else /* RL ratation */
				T=A_DoubleRotateWithRight(T);
	}

	T->height=Max(Height(T->Left),Height(T->Right))+1;
	return T;
}

avltree A_Delete(int element,avltree T) /* delete the integers */
{
	avltree TmpCell;
	if(T==NULL) /* empty tree */
		printf("not found\n");
	else if(element < T->Element) /* smaller than T */
	{
		T->Left=A_Delete(element,T->Left); /* go to the left subtree*/
		if(Height(T->Right)-Height(T->Left)==2) /* unbalance */
			if(Height(T->Right->Left) > Height(T->Right->Right)) /* RL rotation */
				T=A_DoubleRotateWithRight(T);
			else /* RR rotation */
				T=A_SingleRotateWithRight(T);
	}
	else if(element > T->Element) /* larger than T */
	{
		T->Right=A_Delete(element,T->Right); /* go to the right subtree*/
		if(Height(T->Left)-Height(T->Right)==2) /* unbalance */
			if(Height(T->Left->Right) > Height(T->Left->Left)) /* LR rotation */  
				T=A_DoubleRotateWithLeft(T);
			else /* LL rotation */
				T=A_SingleRotateWithLeft(T);
	}
	else /*find the element */
		if(T->Left && T->Right) /* two children */
		{
			TmpCell=A_FindMin(T->Right);
			T->Element=TmpCell->Element;
			T->Right=A_Delete(TmpCell->Element,T->Right);
			if(Height(T->Left)-Height(T->Right)==2) /* unbalance */
			if(Height(T->Left->Right) > Height(T->Left->Left)) /* LR rotation */
				T=A_DoubleRotateWithLeft(T);
			else /* LL rotation */
				T=A_SingleRotateWithLeft(T);
		}
		else /* one or zero child */
		{
			TmpCell=T;
			if(T->Left==NULL)      
				T=T->Right;
			else
				T=T->Left;
			free(TmpCell);
		}

	if(T!=NULL)
		T->height=Max(Height(T->Left),Height(T->Right))+1; /* update the height */
	return T;
}

avltree A_SingleRotateWithLeft(avltree T) /* LL rotation */
{
	avltree A;

	A=T->Left; /* rotate */
	T->Left=A->Right;
	A->Right=T;

	A->height=Max(Height(A->Left),Height(A->Right))+1; /* change height */
	T->height=Max(Height(T->Left),Height(T->Right))+1;

	return A; /* new root */

}

avltree A_SingleRotateWithRight(avltree T) /* RR rotation */
{
	avltree A;

	A=T->Right; /* rotate */
	T->Right=A->Left;
	A->Left=T;

	A->height=Max(Height(A->Left),Height(A->Right))+1; /* change height */
	T->height=Max(Height(T->Left),Height(T->Right))+1;

	return A; /* new root */

}

avltree A_DoubleRotateWithLeft(avltree T) /* LR rotation */
{
	T->Left=A_SingleRotateWithRight(T->Left);/* rotate between the two desandents of T */
	return A_SingleRotateWithLeft(T);/* rotate between T and its son */
}

avltree A_DoubleRotateWithRight(avltree T) /* RL rotation */
{
	T->Right=A_SingleRotateWithLeft(T->Right); /*rotate between the two desandents of T */
	return A_SingleRotateWithRight(T);/* rotate between T and its son */
}

avltree A_FindMin(avltree T) /* find the mininum node in the tree*/
{
	if(T!=NULL)
		while(T->Left!=NULL)
			T=T->Left;

	return T;
}

int Max(int a,int b) /*return the larger number */
{
	if(a>b)
		return a;
	else
		return b;
}

int Height(avltree T) /* calculate the avltree's height */
{
	if(T==NULL)
		return -1;
	else
		return T->height;
}

/************************************ functions about Splay Tree *********************************/

splaytree Sp_Insert(int element,splaytree T) /* insert the integers */
{
	T=S_Insert(element,T); /*insert the integers in a binary search tree */
	T=splay(element,T); /* splay the element which needs to be inserted */

	return T;
}

splaytree Sp_Delete(int element,splaytree T) /* delete the integers */
{
	splaytree TmpCell,New;

	T=splay(element,T); /* splay the node which needs to be deleted */
	if(T->Left!=NULL)
	{
		TmpCell=FindMax(T->Left); /* find the maxmum from the left subtree */
		New=splay(TmpCell->Element,T->Left); /* splay the maxmum node of the left subtree */
		New->Right=T->Right; /* then the left subtree has a root which dosen't have right child so connect it with the right subtree*/
	}
	else
		New=T->Right;
	free(T); /*delete the node which needs to be deleted */

	return New;
}

splaytree FindMax(splaytree T) /* find the maxmum in a tree */
{
	if(T!=NULL)
		while(T->Right!=NULL)
			T=T->Right;

	return T;
}

splaytree splay(int element,splaytree T) /* splay at the node element */
{
	splaytree TmpCell; /* TmpCell points to the root */
	splaytree Father;  /* Father points to the father node of T */

	for(;T->Element!=element && T!=NULL;) /* splay until the root is the element */
	{
		if(T->Right!=NULL && T->Right->Element == element) /* the element is the right son of the root */
		{
			T=Sp_SingleRotateWithRight(T); /* right rotate */
			break;
		}
		else if(T->Left!=NULL && T->Left->Element == element) /* the element is the left son of the root */
		{
			T=Sp_SingleRotateWithLeft(T); /* left rotate */
			break;
		}
		else if(T->Right!=NULL && T->Right->Right!=NULL && T->Right->Right->Element == element) /* zig-zig */
		{
			T=Sp_SingleRotateWithRight(T);
			T=Sp_SingleRotateWithRight(T);
			break;
		}
		else if(T->Right!=NULL && T->Right->Left!=NULL && T->Right->Left->Element == element) /* zig-zag */
		{
			T=Sp_DoubleRotateWithRight(T); /* RL rotate */
			break;
		}
		else if(T->Left!=NULL && T->Left->Left!=NULL && T->Left->Left->Element == element) /* zig-zig */
		{
			T=Sp_SingleRotateWithLeft(T);
			T=Sp_SingleRotateWithLeft(T);
			break;
		}
		else if(T->Left!=NULL && T->Left->Right!=NULL && T->Left->Right->Element == element) /* zig-zag */
		{
			T=Sp_DoubleRotateWithLeft(T); /* LR rotate */
			break;
		}
		else /* the element is neither the son nor the grandson of the root */
			for(TmpCell=T;;) /* splay until the element is the son or the grandson of the root*/
			{
                if(TmpCell->Right!=NULL && TmpCell->Right->Right!=NULL && TmpCell->Right->Right->Element == element) /* zig-zig */
				{
					if(Father->Left!=NULL && Father->Left->Element == TmpCell->Element)
					{
						TmpCell=Sp_SingleRotateWithRight(TmpCell);
						Father->Left=Sp_SingleRotateWithRight(TmpCell);
					}
					else
					{
						TmpCell=Sp_SingleRotateWithRight(TmpCell);
						Father->Right=Sp_SingleRotateWithRight(TmpCell);
					}

					break;
				}

				else if(TmpCell->Right!=NULL && TmpCell->Right->Left!=NULL && TmpCell->Right->Left->Element == element)  /* zig-zag */
				{
					if(Father->Left!=NULL && Father->Left->Element == TmpCell->Element)
						Father->Left=Sp_DoubleRotateWithRight(TmpCell);
					else
						Father->Right=Sp_DoubleRotateWithRight(TmpCell);

					break;
				}
				else if(TmpCell->Left!=NULL && TmpCell->Left->Left!=NULL && TmpCell->Left->Left->Element == element) /* zig-zig */
				{
					if(Father->Left!=NULL && Father->Left->Element == TmpCell->Element)
					{
						TmpCell=Sp_SingleRotateWithLeft(TmpCell);
						Father->Left=Sp_SingleRotateWithLeft(TmpCell);
					}
					else
					{
						TmpCell=Sp_SingleRotateWithLeft(TmpCell);
						Father->Right=Sp_SingleRotateWithLeft(TmpCell);
					}

					break;
				}
				else if(TmpCell->Left!=NULL && TmpCell->Left->Right!=NULL && TmpCell->Left->Right->Element == element)  /* zig-zag */
				{
					if(Father->Left!=NULL && Father->Left->Element == TmpCell->Element)
						Father->Left=Sp_DoubleRotateWithLeft(TmpCell);
					else
						Father->Right=Sp_DoubleRotateWithLeft(TmpCell);

					break;
				}
				/* the element is neither the son nor the grandson of the root */
				else if(TmpCell->Element < element) /* the element in the right subtree of T*/
				{
					Father=TmpCell; /* reserve the father node of T */
					TmpCell=TmpCell->Right; /*move down the T to deep splay*/
				}
				else /* the element in the left subtree of T*/
				{
					Father=TmpCell; /* reserve the father node of T */
					TmpCell=TmpCell->Left; /*move down the T to deep splay*/
				}
			}
	}

	return T;
}

splaytree Sp_SingleRotateWithLeft(splaytree T) /* left rotate */
{
	splaytree A;

	A=T->Left; /* rotate */
	T->Left=A->Right;
	A->Right=T;

	return A; /* new root */
}

splaytree Sp_SingleRotateWithRight(splaytree T) /* right rotate */
{
	splaytree A;

	A=T->Right; /* rotate */
	T->Right=A->Left;
	A->Left=T;

	return A; /* new root */
}

splaytree Sp_DoubleRotateWithLeft(splaytree T) /* LR rotate */
{
	T->Left=Sp_SingleRotateWithRight(T->Left);/* rotate between the two desandents of T */
	return Sp_SingleRotateWithLeft(T);/* rotate between T and its son */
}

splaytree Sp_DoubleRotateWithRight(splaytree T) /* RL rotate */
{
	T->Right=Sp_SingleRotateWithLeft(T->Right);/* rotate between the two desandents of T */
	return Sp_SingleRotateWithRight(T);/* rotate between T and its son */
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
岛国一区二区在线观看| 欧美日韩亚洲不卡| 久久久久久毛片| 精品一区精品二区高清| 欧美成人三级在线| 国产一区二区0| 中文字幕av不卡| 91丨九色丨国产丨porny| 成人欧美一区二区三区黑人麻豆 | 福利91精品一区二区三区| 国产欧美精品一区| 99精品欧美一区二区三区综合在线| 欧美精品久久久久久久多人混战| 亚洲乱码中文字幕| 91香蕉视频mp4| 亚洲精品日日夜夜| 欧美性猛片xxxx免费看久爱| 天堂精品中文字幕在线| 精品国产亚洲在线| 高清在线成人网| 亚洲女同一区二区| 欧美一卡二卡在线| 国产91丝袜在线播放九色| 亚洲精选视频在线| 欧美第一区第二区| 国产成人三级在线观看| 一区二区三区在线观看网站| 日韩一区二区精品葵司在线| 福利一区福利二区| 亚洲大片免费看| 国产视频一区二区三区在线观看| 色婷婷精品久久二区二区蜜臂av| 首页国产欧美久久| 中文字幕不卡在线观看| 7777精品伊人久久久大香线蕉经典版下载| 久久91精品国产91久久小草| 亚洲欧美日韩小说| 欧美r级在线观看| 91福利国产精品| 国产激情91久久精品导航| 一区二区三区精品| 久久精品亚洲精品国产欧美kt∨| 欧美在线看片a免费观看| 国产一区二区在线看| 亚洲国产乱码最新视频| 国产精品黄色在线观看| 欧美精品高清视频| 一本久久a久久免费精品不卡| 老司机精品视频导航| 一区二区三区久久久| 欧美本精品男人aⅴ天堂| 欧美三级日本三级少妇99| 成人一区二区视频| 久久99精品国产| 日韩av电影天堂| 亚洲尤物视频在线| 中文字幕在线不卡一区二区三区| 欧美xxx久久| 欧美一区二区三区婷婷月色| 在线观看av一区| 91免费在线视频观看| 成人综合婷婷国产精品久久免费| 麻豆91小视频| 亚洲chinese男男1069| 伊人色综合久久天天| 欧美激情一区在线观看| 久久久久国产成人精品亚洲午夜| 欧美一区二区三区婷婷月色| 欧美精品久久天天躁| 欧美二区乱c少妇| 在线观看91视频| 欧美性受xxxx黑人xyx性爽| 91色乱码一区二区三区| 成人av电影在线播放| 成人伦理片在线| 成人国产精品免费观看视频| 国产成人午夜精品影院观看视频 | 一区二区三区免费| 亚洲女爱视频在线| 亚洲日本va午夜在线影院| 国产精品午夜免费| 中文字幕在线不卡国产视频| 中文字幕一区二区三区乱码在线| 国产精品色哟哟| 亚洲欧洲精品一区二区三区| 1024精品合集| 亚洲精品国产精华液| 亚洲国产一区二区三区青草影视| 亚洲高清视频的网址| 日本特黄久久久高潮| 九色综合狠狠综合久久| 国产大陆精品国产| 不卡的电影网站| 色综合久久综合| 91福利资源站| 日韩午夜在线播放| 久久久久久**毛片大全| ...xxx性欧美| 亚洲精品成人少妇| 日本aⅴ亚洲精品中文乱码| 另类调教123区 | 欧美午夜精品理论片a级按摩| 欧美日韩在线电影| 欧美成人精品高清在线播放| 欧美韩国日本不卡| 一区二区三区在线看| 免费观看成人av| heyzo一本久久综合| 91传媒视频在线播放| 日韩精品中文字幕一区二区三区 | 亚洲精品va在线观看| 国产精品538一区二区在线| 亚洲18影院在线观看| 久久精品二区亚洲w码| 国产成人啪午夜精品网站男同| 99久久99久久精品免费观看| 欧美人狂配大交3d怪物一区| 精品处破学生在线二十三| 国产精品国产馆在线真实露脸 | 日韩一二在线观看| 国产精品免费av| 香蕉av福利精品导航| 国产乱子伦一区二区三区国色天香| 99久久99精品久久久久久 | 国产乱码精品一区二区三| 99视频在线观看一区三区| 欧美日韩中字一区| 国产视频一区二区在线| 视频一区视频二区中文字幕| 成人高清视频在线| 日韩一区二区三区在线观看| 国产精品久久久久久久浪潮网站| 日韩成人午夜精品| 色综合久久久久久久久久久| 欧美刺激午夜性久久久久久久| 悠悠色在线精品| 成人黄色大片在线观看| 日韩一级视频免费观看在线| 最新国产精品久久精品| 国产一区二区三区观看| 亚洲国产综合在线| 国产一区二区免费看| 欧美性极品少妇| 国产精品入口麻豆九色| 免费一级片91| 欧美性受极品xxxx喷水| 亚洲丝袜精品丝袜在线| 国产激情视频一区二区三区欧美| 91麻豆精品国产91久久久 | 欧美一区二区视频观看视频| 亚洲在线观看免费视频| 成人高清在线视频| 国产欧美日韩亚州综合| 国产资源在线一区| 日韩一二在线观看| 日韩精品欧美成人高清一区二区| 色综合天天天天做夜夜夜夜做| 国产亚洲制服色| 国产成人三级在线观看| 久久久久国产精品免费免费搜索| 久久电影网电视剧免费观看| 91精品在线观看入口| 香蕉成人啪国产精品视频综合网| 欧美亚洲动漫制服丝袜| 亚洲第一二三四区| 欧美丰满美乳xxx高潮www| 日日夜夜一区二区| 4438x成人网最大色成网站| 午夜一区二区三区在线观看| 欧美少妇xxx| 天天射综合影视| 欧美一区二区日韩| 精品一区二区三区欧美| 精品粉嫩超白一线天av| 国产美女精品在线| 久久女同精品一区二区| 国产麻豆精品视频| 国产精品色在线| 色婷婷亚洲综合| 日本欧洲一区二区| 久久久久久久久蜜桃| 国产成人av影院| 亚洲欧美日韩中文字幕一区二区三区| 91免费观看视频| 性做久久久久久免费观看欧美| 欧美日韩精品三区| 日产精品久久久久久久性色| 在线播放欧美女士性生活| 亚洲电影中文字幕在线观看| 成人动漫一区二区在线| 欧美高清一级片在线观看| 风间由美一区二区av101| 国产精品乱人伦一区二区| 成a人片亚洲日本久久| 中文字幕一区二区三区不卡在线| 高清在线观看日韩| 亚洲人妖av一区二区| 色综合久久久久网| 亚洲欧洲av在线| 欧美精品久久久久久久多人混战 |