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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? library.cpp

?? b樹的C++實現(xiàn),運用模板實現(xiàn)B樹 簡單明了
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
		result = success;
	}
	return result;
}

template<class Type,int order>
Error_code B_tree<Type,order>::recursive_borrow(B_node<Type,order> *current,const Type &target,int number)
{
	Error_code result;
	int position;
	if(current != NULL)
	{
		result = search_node(current,target,position);
		if(result == not_present)
		{
			result = recursive_borrow(current->branch[position],target,number);
		}
		else
		{
			if(current->data[position].get_state() == true)
			{
				result = success;
				if(current->data[position].get_amount() <  number)
				{
					cout<<"You can only borrow "<<current->data[position].get_amount()<<" books"<<endl;
				}
				else
				{
					current->data[position].set_amount(current->data[position].get_amount() - number);
					//cout<<current->data[position].get_amount()<<endl;
					if(current->data[position].get_amount() <= 0)
					{
						current->data[position].set_state(false);
						//cout<<current->data[position].get_amount()<<endl;
						//cout<<current->data[position].get_state()<<endl;
					}
				}
				
			}
			else
			{
				result = already_out;
				cout<<"This book has been borrowed!"<<endl;
			}
			
		}
	}
	return result;
}

template<class Type,int order>
Error_code B_tree<Type ,order>::borrow(const Type &target,int number)
{
	return recursive_borrow(root,target,number);
}

template<class Type,int order>
Error_code B_tree<Type,order>::recursive_return(B_node<Type,order> *current,const Type &target,int number)
{
	if(number <= 0)
	{
		cout<<"The number of return books must be larger than 0!"<<endl;
		return error;
	}
	else
	{
		Error_code result;
	int position;
	if(current != NULL)
	{
		result = search_node(current,target,position);
		if(result == not_present)
		{
			result = recursive_return(current->branch[position],target,number);
		}
		else
		{
			result = success;
			current->data[position].set_amount(current->data[position].get_amount() + number);
			current->data[position].set_state(true);
		}
	}
	return result;
	}
}

template<class Type,int order>
Error_code B_tree<Type,order>::return_book(const Type &target,int number)
{
	return recursive_return(root,target,number);
}

//刪除部分
template<class Type,int order>
void B_tree<Type,order>::remove_data(B_node<Type,order> *current,int position)
{
	for(int i = position;i < current->count-1;i++)
		current->data[i] = current->data[i+1];
	current->count--;
}

template<class Type,int order>
void B_tree<Type,order>::copy_in_predecessor(B_node<Type,order> *current,int position)
{
	B_node<Type,order> *leaf = current->branch[position];
	while(leaf->branch[leaf->count] != NULL)
		leaf = leaf->branch[leaf->count];
	current->data[position] = leaf->data[leaf->count-1];
}

template<class Type,int order>
void B_tree<Type,order>::move_left(B_node<Type,order> *current,int position)
{
	B_node<Type,order>* left_branch = current->branch[position-1];
	B_node<Type,order>* right_branch = current->branch[position];
	left_branch->data[left_branch->count] = current->data[position-1];
	left_branch->branch[++left_branch->count] = right_branch->branch[0];
	current->data[position-1] = right_branch->data[0];
	right_branch->count--;
	for(int i = 0;i < right_branch->count;i++)
	{
		right_branch->data[i] = right_branch->data[i+1];
		right_branch->branch[i] = right_branch->branch[i+1];
	}
	right_branch->branch[right_branch->count] = right_branch->branch[right_branch->count+1];
}

template<class Type,int order>
void B_tree<Type,order>::move_right(B_node<Type,order> *current,int position)
{
	B_node<Type,order>* right_branch = current->branch[position+1];
	B_node<Type,order>* left_branch = current->branch[position];
	right_branch->branch[right_branch->count+1] = right_branch->branch[right_branch->count];
	for(int i = right_branch->count;i > 0;i--)
	{
		right_branch->data[i] = right_branch->data[i-1];
		right_branch->branch[i] = right_branch->branch[i-1];
	}
	right_branch->count++;
	right_branch->data[0] = current->data[position];
	right_branch->branch[0] = left_branch->branch[left_branch->count--];
	current->data[position] = left_branch->data[left_branch->count];
}

template<class Type,int order>
void B_tree<Type,order>::combine(B_node<Type,order> *current,int position)
{
	int i;
	B_node<Type,order>* left_branch = current->branch[position-1];
	B_node<Type,order>* right_branch = current->branch[position];
	left_branch->data[left_branch->count] = current->data[position-1];
	left_branch->branch[++left_branch->count] = right_branch->branch[0];
	for(i = 0;i < right_branch->count;i++)
	{
		left_branch->data[left_branch->count] = right_branch->data[i];
		left_branch->branch[++left_branch->count] = right_branch->branch[i+1];
	}
	current->count--;
	for(i = position-1;i < current->count;i++)
	{
		current->data[i] = current->data[i+1];
		current->branch[i+1] = current->branch[i+2];
	}
	delete right_branch;
}

template<class Type,int order>
void B_tree<Type,order>::restore(B_node<Type,order> *current,int position)
{
	if(position == current->count)
	{
		if(current->branch[position-1]->count > (order-1)/2)
			move_right(current,position-1);
		else
			combine(current,position);
	}
	else if(position == 0)
	{
		if(current->branch[1]->count > (order-1)/2)
			move_left(current,1);
		else
			combine(current,1);
	}
	else
	{
		if(current->branch[position-1]->count > (order-1)/2)
			move_right(current,position-1);
		else if(current->branch[position+1]->count > (order-1)/2)
			move_left(current,position+1);
		else
			combine(current,position);
	}
}

template<class Type,int order>
Error_code B_tree<Type,order>::recursive_remove(B_node<Type,order> *current,const Type &target)
{
	Error_code result;
	int position;
	if(current == NULL)
		result = not_present;
	else
	{
		if(search_node(current,target,position) == success)
		{
			result = success;
			if(current->branch[position] != NULL)
			{
				copy_in_predecessor(current,position);
				recursive_remove(current->branch[position],current->data[position]);
			}
			else
				remove_data(current,position);
		}
		else
			result = recursive_remove(current->branch[position],target);
		if(current->branch[position] != NULL)
		{
			if(current->branch[position]->count < (order-1)/2)
				restore(current,position);
		}
	}
	return result;
}

template<class Type,int order>
Error_code B_tree<Type,order>::remove(const Type &target)
{
	Error_code result;
	result = recursive_remove(root,target);
	if(root != NULL && root->count == 0)
	{
		B_node<Type,order> *old_root = root;
		root = root->branch[0];
		delete old_root;
	}
	return result;
}

template <class Type,int order>
void B_tree<Type,order>::level_scan(B_node<Type,order>* root)//按層次遍歷
{
	queue<B_node<Type,order>* > q1,q2,temp;//q1存放當前層節(jié)點 q2存放下一層節(jié)點
	B_node<Type,order>*p;
	int level=0;
	if( root!=NULL)
	{
		q1.push(root);
		while( !q1.empty())
		{
			int num=q1.size();//處理當前層
			level++;
			cout<<"第"<<level<<"層:";
			for(int i=0;i<num;i++)
			{
				p=q1.front();
				q1.pop();
				
				for( int j=0;j<p->count;j++)
				{
					cout<<p->data[j]<<"     ";
				}
				
				for( int k=0;k<=p->count;k++)
				{
					if( p->branch[k]!=NULL)
						q2.push(p->branch[k]);
				}
			}
			cout<<endl ;// finish a leve 
			q1=q2;
			q2=temp;
		}
	}
}

template <class Type,int order>
void B_tree<Type,order>::recursive_inorder(B_node<Type,order>*root)//中序遍歷(順序遍歷)
{
	if(root!=NULL)
	{
		for( int i=0;i<root->count;i++)
		{
			recursive_inorder(root->branch[i]);
			cout<<root->data[i]<<endl;
		}
		recursive_inorder(root->branch[i]);
	}
}

int main()
{
	Book book1("1","os","arm",19);
	Book book2("2","se","arm",9);
	Book book3("3","db","mike",7);
	Book book4("4","c++","mike",7);
	Book book5("5","java","mike",7);
	Book book6("6","j2ee","mike",5);
	Book book7("7","uml","jackson",6);
	Book book8("8","xml","rolex",7);
	Book book9("9","windows","mike",7);
	Book book10("1","os","arm",2);
	B_tree<Book,5> library;
	library.insert(book1);
	library.insert(book3);
	library.insert(book4);
	library.insert(book2);
	library.insert(book5);
	library.insert(book6);
	library.insert(book7);
	library.insert(book8);
	library.insert(book9);
	library.insert(book10);
	//library.borrow(book1,10);
	library.borrow(book2,9);
	//library.borrow(book2,1);
	library.return_book(book2,3);
	library.borrow(book2,3);
	//library.borrow(book2,4);
	//library.remove(book1);
	//cout<<book1.get_amount()<<endl;
	library.level_scan(library.GetRoot());
	//library.recursive_inorder(library.GetRoot());

	return 0;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美人牲a欧美精品| 日韩毛片在线免费观看| 日韩精品一区二区在线| 国产精品久久久久久久裸模| 亚洲丰满少妇videoshd| 高清在线成人网| 欧美久久久久久蜜桃| 亚洲欧美一区二区在线观看| 极品尤物av久久免费看| 在线观看国产91| 中文字幕一区av| 国产美女主播视频一区| 4438x亚洲最大成人网| 亚洲色图一区二区| 成人免费av资源| 久久色在线视频| 日本午夜一本久久久综合| 欧美性猛片xxxx免费看久爱| 国产精品拍天天在线| 国产一区二区三区最好精华液| 欧美精品tushy高清| 一区二区三区日韩精品视频| heyzo一本久久综合| 久久久精品国产免大香伊| 国内精品视频一区二区三区八戒| 欧美精品免费视频| 亚洲国产另类av| 欧美日韩高清影院| 亚洲h精品动漫在线观看| 色一情一伦一子一伦一区| 国产精品电影一区二区三区| 国产mv日韩mv欧美| 国产精品午夜在线观看| 国产.欧美.日韩| 欧美国产欧美亚州国产日韩mv天天看完整| 久久国产综合精品| 精品不卡在线视频| 国产一区二区在线影院| 国产欧美日韩三级| 波多野结衣的一区二区三区| 国产精品青草综合久久久久99| 成人av电影观看| 亚洲欧美日韩一区| 欧美日韩在线观看一区二区 | 欧美日韩久久一区二区| 一区二区三区中文字幕电影| 在线观看日韩国产| 日本va欧美va精品| 精品国产一区二区三区四区四| 激情综合色播激情啊| 精品福利av导航| 成人av电影在线| 亚洲18色成人| 欧美tickling挠脚心丨vk| 国产成人精品一区二| 亚洲色图制服诱惑| 制服丝袜激情欧洲亚洲| 极品少妇一区二区三区精品视频| 国产欧美一区二区三区在线看蜜臀 | 图片区日韩欧美亚洲| 欧美一级高清片| 丁香婷婷综合色啪| 亚洲影视在线播放| 日韩欧美不卡一区| 91视频国产资源| 日本中文一区二区三区| 国产精品伦理一区二区| 欧美日韩三级视频| 国产成人av电影免费在线观看| 亚洲精品ww久久久久久p站 | 欧美午夜在线观看| 国精品**一区二区三区在线蜜桃| 国产精品网站一区| 欧美精品一卡两卡| 国产91在线|亚洲| 亚洲成在人线免费| 中国色在线观看另类| 欧美日韩国产片| 成人av动漫在线| 国产专区欧美精品| 亚洲va天堂va国产va久| 日韩美女视频一区二区| 亚洲精品一区二区三区四区高清| 99re6这里只有精品视频在线观看| 婷婷久久综合九色国产成人 | 精品国产成人系列| 欧美日韩国产综合一区二区| 成人免费视频播放| 久久99精品久久久久久动态图 | 成人精品国产福利| 老司机精品视频在线| 亚洲一区二区黄色| 亚洲同性gay激情无套| 久久久久久一二三区| 欧美一区二区私人影院日本| 在线观看国产91| 99国内精品久久| 丁香啪啪综合成人亚洲小说| 韩国精品在线观看| 美女一区二区久久| 蜜桃视频第一区免费观看| 樱花影视一区二区| 日韩美女啊v在线免费观看| 亚洲国产精品二十页| 精品国产免费一区二区三区四区| 欧美久久久久免费| 欧美私人免费视频| 日本黄色一区二区| 日本韩国一区二区| 91麻豆精品在线观看| 成人18精品视频| 波多野结衣亚洲| 北条麻妃国产九九精品视频| 成人精品国产一区二区4080| 成人黄色电影在线| 一本久道久久综合中文字幕 | 亚洲一区二区精品3399| 一级精品视频在线观看宜春院| 亚洲三级免费电影| 亚洲综合色成人| 天天av天天翘天天综合网| 丝袜美腿亚洲一区| 久久精品久久综合| 国产a久久麻豆| 色欧美片视频在线观看| 欧美日韩国产影片| 欧美成人r级一区二区三区| 精品91自产拍在线观看一区| 国产日韩欧美不卡| ...xxx性欧美| 香蕉久久一区二区不卡无毒影院| 日本欧美久久久久免费播放网| 免费观看日韩电影| 成人精品视频一区二区三区尤物| 成人天堂资源www在线| 在线亚洲一区二区| 欧美一级高清片在线观看| 国产亚洲制服色| 国产精品超碰97尤物18| 三级不卡在线观看| 国产一区二区三区高清播放| 91在线一区二区三区| 欧美丰满少妇xxxxx高潮对白| 337p粉嫩大胆噜噜噜噜噜91av| 国产精品嫩草影院av蜜臀| 亚洲午夜羞羞片| 国产乱码精品一品二品| 在线区一区二视频| 精品久久免费看| 亚洲激情中文1区| 久久99精品一区二区三区三区| 高清不卡在线观看| 欧美男人的天堂一二区| 国产午夜精品一区二区三区嫩草| 自拍偷自拍亚洲精品播放| 日本91福利区| 91啪亚洲精品| 久久久午夜精品理论片中文字幕| 亚洲人被黑人高潮完整版| 久久99久久99| 欧美精选午夜久久久乱码6080| 欧美激情资源网| 美美哒免费高清在线观看视频一区二区| 成人av资源网站| 欧美va在线播放| 调教+趴+乳夹+国产+精品| 国产不卡在线播放| 日韩亚洲电影在线| 亚洲曰韩产成在线| 国产成人av影院| 日韩欧美在线123| 亚洲成av人片观看| 色嗨嗨av一区二区三区| 亚洲国产精品成人综合| 精品一区二区免费看| 欧美老人xxxx18| 夜夜精品视频一区二区| 成人久久18免费网站麻豆| 精品国产免费视频| 美腿丝袜亚洲综合| 欧美日韩在线一区二区| 亚洲另类春色国产| 91色九色蝌蚪| 国产亚洲一区二区三区| 激情国产一区二区| 91精品国产综合久久久蜜臀图片| 亚洲一区二区欧美| 精品视频一区二区三区免费| 亚洲精品国产第一综合99久久| 成人小视频免费在线观看| 国产性天天综合网| 国产精品99久久久久久宅男| 久久影院午夜论| 国产精品99久| 国产亚洲成aⅴ人片在线观看 | 欧美日韩在线一区二区| 亚洲综合视频在线| 欧美日本一道本| 日日夜夜免费精品| 日韩欧美一级片|