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

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

?? 排序 -- 二叉樹排序[anank].cpp

?? 包含選擇排序法
?? CPP
字號:
/******************************************************************************************************
** Program Name : Binary Search Tree
** Author       : Lu Jian Hua
** Time         : 2007-6-2
*******************************************************************************************************/

#include <iostream>
using namespace std ;

const int LEFT  = 0 ;				
const int RIGHT = 1 ;

/*-------------------------------------Class Node ( Node Of BTree )----------------START--------------------*/
class Node													// Node of tree
{
public:
	char c ;												// data  portion
	Node *L_Child ;											// left  child 
	Node *R_Child ;											// right child 
	Node *next ;
	Node() : c(0), L_Child(NULL), R_Child(NULL)	{}
	Node(char ch) : c(ch), L_Child(NULL), R_Child(NULL), next(NULL) {}
} ;
/*-------------------------------------Class Node ( Node Of BTree )-----------------END---------------------*/


/*--------------------------------------Class Stack---------------------------------START-------------------*/
class Stack
{
public:
	Stack(int max_size) ;					// constructor
	Node*  GetTopValue() const ;			// get the top value of stack
	void Push(Node* value) ;				// push
	Node*  Pop() ;							// pop
	void Init() ;							// initialize the stack
	bool IsEmpty() ;						// is empty ?
private:
	enum { MAX_SIZE = 100 } ;
	int top ;
	Node* element[MAX_SIZE] ;
} ;


Stack::Stack(int max_size) : top(-1) {}

Node* Stack::GetTopValue() const
{
	if (top < 0)
	{
		return 0 ;
	}

	return element[top] ;
}

void Stack::Push(Node* value)				// Operation:push a element into stack
{
	if (top >= MAX_SIZE-1)
	{
		cout << "The stack is full!    " << endl << endl ;
		return ;
	}

	top++ ;									// 1> move the top pointer
	element[top] = value ;					// 2> infill the space top pointer directing
}

Node* Stack::Pop()							// Operation:Pop a element from stack
{
	if (top < 0)
	{
		return 0 ;
	}

	Node* temp = element[top] ;				// 1> get the value
	top-- ;									// 2> move the top pointer
	return temp ;
}

void Stack::Init()
{
	top = -1 ;
}

bool Stack::IsEmpty()						// test if the stack is empty ?
{
	return ( top < 0 ) ;
}
/*--------------------------------------Class Stack---------------------------------END---------------------*/


/*--------------------------------------Class Queue---------------------------------START-------------------*/

class Queue									// class of Queue
{
public:
	Queue() ;
	Node*  GetValue() const ;				// get the current value of Queue
	Node*  Delete() ;						// out_Queue
	void Append(Node* value) ;				// In__Queue				
	bool IsEmpty() const ;					// is empty ?
	bool IsFull()  const ;					// is full ?
private:
	int front ;								// front
	int rear  ;								// rear
	enum { MAX_SIZE = 500 } ;				// Notice:remember ; at the end
	Node* element[MAX_SIZE] ;				// implement with array
} ;

Queue::Queue() : front(0), rear(0) {}

Node* Queue::GetValue() const
{
	if ( IsEmpty() )
	{
		cout << "The queue is empty!" << endl << endl ;
		return 0 ;
	}

	int temp = front ;
	return element[++temp] ;		
}

void Queue::Append(Node* value)
{
	if ( IsFull() )
	{
		cout << "The queue is full!" << endl << endl ;
		return ;
	}

	rear = (rear+1) % MAX_SIZE ;
	element[rear] = value ;
}

Node* Queue::Delete()
{
	if ( IsEmpty() )
	{
		cout << "The queue is empty!" << endl << endl ;
		return 0 ;
	}

	//return element[(++front) % MAX_SIZE] ;					// different from the next sentence??
	front = (front+1) % MAX_SIZE ;
	return element[front] ;
}

bool Queue::IsEmpty() const						
{
	return (rear == front) ;
}

bool Queue::IsFull()  const
{
	return ( (rear+1) % MAX_SIZE == front ) ;
}

/*--------------------------------------Class Queue---------------------------------END---------------------*/


/*--------------------------------------GLOBAL VARIABLE-----------------------------START-------------------*/
Node* TAG = (Node*)10000 ;
const int ROW = 80 ;
const int COL = 80 ;
char a[ROW][COL] ;
Node *RFPrint = NULL ;	// root_for_print
/*--------------------------------------GLOBAL VARIABLE-----------------------------END---------------------*/

void operator <<(ostream os, Node node)		//-------------- output a node directly ----------------------
{
	os << node.c << " " ;
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Add_New_Node
** Parameters    : Node **root
**               : Node *temp	(any node)
** Return Value  : void
** Details       : add a new node into a binary search tree
**--------------------------------------------------------------------------------------------------------*/
void Add_New_Node(Node **root, Node *temp)
{
	if (*root == NULL)
	{
		*root = temp ;
		return ;
	}

	if ( temp->c < (*root)->c )
		root = &( (*root)->L_Child ) ;
	else
		root = &( (*root)->R_Child ) ;

	Add_New_Node(root, temp) ;
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Print
** Parameters    : Node *root	(the root of a binary tree)
**				   int x		(x coordinate of the certain node)
**				   int y		(y coordinate of the certain node)
** Return Value  : void
** Details       : print the architecture to a table
**--------------------------------------------------------------------------------------------------------*/
void Print(Node *r, int x, int y)		// r==root, a=arry, x=coordinate x, y=coordinate y
{
	Queue queue ;
	static Queue *q = &queue ;

	if (r == NULL)
		return ;

	q->Append(r) ;					

	while (q->IsEmpty() == false)
	{
		Node *temp = q->Delete() ;
		a[x][y] = temp->c ;

		if (temp->L_Child)
			a[x+1][y-1] = '/' ;
		if (temp->R_Child)
			a[x+1][y+1] = '\\' ;

		if (temp->L_Child)
			q->Append(temp->L_Child) ;
		if (temp->R_Child)
			q->Append(temp->R_Child) ;
	}
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Get_Node_Rank
** Parameters    : Node *root	(the root of a binary tree)
**				   Node *recent	(the recent node to be disposed)
** Return Value  : void
** Details       : get the rank of a certain node in the binary tree
**				   root : 1
**				   .... : 2
**				   .... : 3
**				   .... : 4 
**				   ........
**--------------------------------------------------------------------------------------------------------*/
int Get_Node_Rank(Node *root, Node *recent)
{
	bool found = false ;
	int count = 0 ;
	Stack s(100) ;					// the stack may be used

	while (root)
	{
		s.Push(root) ;
		if ( s.GetTopValue() == recent )
		{
			found = true ;
			break ;
		}
		else
			root = root->L_Child ;

		if (root == NULL)
		{
			Node *temp = s.GetTopValue() ;
			s.Push(TAG) ;
			root = temp->R_Child ;
			if (root == NULL)
			{
				while (true)
				{
					if (s.GetTopValue() == TAG)
					{	
						s.Pop() ;	
						s.Pop() ;	
					}
					else
					{	
						if (s.GetTopValue() == NULL)
							cout << "Null Pointer Exists..." << endl << endl ;
						root = ( s.GetTopValue()) ->R_Child ;
						if (root == NULL)
						{
							s.Pop() ;
							continue ;
						}
						else
						{
							s.Push(TAG) ;
							break ;
						}
					}
				}
			}
		}
	}

	if (found)
	{
		while (s.IsEmpty() == false)
		{
			if (s.Pop() != TAG)
				count ++ ;
		}
	}
	else
		return 0 ;

	return count ;
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Print_Tree
** Parameters    : Node *root	(the root of a binary tree)
**				   int x		(x coordinate of the certain node)
**				   int y		(y coordinate of the certain node)
** Return Value  : void
** Details       : print the architecture to the screen(through a table)
**--------------------------------------------------------------------------------------------------------*/
void Print_Tree(Node *r, int x, int y)
{
	int num = ( Get_Node_Rank(RFPrint, r) <= 7 ? (8-Get_Node_Rank(RFPrint,r)) : 1 ) ;
	a[x][y] = r->c ;
	for (int i=1; i<=num; i++)
	{
		if (r->L_Child)
			a[x+i][y-i] = '/' ;
		if (r->R_Child)
			a[x+i][y+i] = '\\' ;
	}

	if (r->L_Child)
	{
		Print_Tree(r->L_Child, x+(num+1), y-(num+1)) ;
	}
	if (r->R_Child)
	{
		Print_Tree(r->R_Child, x+(num+1), y+(num+1)) ;
	}
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Init_Table
** Parameters    : NULL
** Return Value  : void
** Details       : initialize all the elements of the table with NULL character
**--------------------------------------------------------------------------------------------------------*/
void Init_Table()
{
	for (int i=0; i<ROW; i++)					// initialize the char table
		for (int j=0; j<COL; j++)
			a[i][j] = ' ' ;
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Print_Table
** Parameters    : NULL
** Return Value  : void
** Details       : print the table to the screen
**--------------------------------------------------------------------------------------------------------*/
void Print_Table()
{
	for (int i=0; i<ROW; i++)						// print the tree
		for (int j=0; j<COL; j++)
			cout << a[i][j] ;
}
/*--------------------------------------------------------------------------------------------------------
** Function Name : Build_BSTree
** Parameters    : Node **root		
** Return Value  : void
** Details       : Build a binary search tree
**--------------------------------------------------------------------------------------------------------*/
void Build_BSTree(Node **root)
{
	while (true)
	{
		char c = 0 ;
		cout << "Another Node ? (Y/N) " ;
		cin  >> c;

		if (c != 'n' && c != 'N')
		{
			Node *temp = new Node() ;
			cout << "Please Enter The Value : " ;
			cin  >> temp->c ;
			temp->L_Child = temp->R_Child = NULL ;

			Add_New_Node(root, temp) ;
		}
		else
			break ;
	}
}


int main()
{
	Node *root = NULL ;							

	Build_BSTree(&root) ;						// build the Binary Search Tree

	/*---------------------------------- Print The Tree ----------------------------------*/
	Init_Table() ;
	RFPrint = root ;
	Print_Tree(root, 0, 40) ;				
	Print_Table() ;
	/*---------------------------------- Print The Tree ----------------------------------*/

	return 0 ;
}




/********************************************************************************
*
* Notice : This Program Can Be Launched In VC6.0 Environment
*
********************************************************************************/

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品99国产国产精| 亚洲一区二区三区四区五区中文 | 一区二区三区久久| 国产精品资源站在线| 久久久精品人体av艺术| 美女视频黄a大片欧美| 日韩一区二区在线看| 日韩精品亚洲专区| 欧美精品久久久久久久多人混战 | 色偷偷久久一区二区三区| 亚洲欧洲精品一区二区三区| 97aⅴ精品视频一二三区| 国产亚洲人成网站| 99re热这里只有精品免费视频| 综合久久久久久久| 在线观看网站黄不卡| 亚洲gay无套男同| 欧美大白屁股肥臀xxxxxx| 免费成人av资源网| 亚洲国产精品av| 欧美影视一区在线| 另类小说色综合网站| 亚洲国产高清aⅴ视频| 色综合天天综合色综合av| 亚洲午夜私人影院| 日本视频在线一区| 久久久久久综合| 一本色道a无线码一区v| 蜜臀国产一区二区三区在线播放| 久久影院电视剧免费观看| 91亚洲精品久久久蜜桃| 奇米亚洲午夜久久精品| 欧美国产日本韩| 欧美猛男gaygay网站| 国产成人在线色| 亚洲在线视频网站| 国产亚洲美州欧州综合国| 欧美性生活影院| 国产成人午夜电影网| 婷婷开心久久网| 国产精品久久久久一区二区三区| 欧美一区二区三级| 91美女精品福利| 国产成人久久精品77777最新版本| 亚洲国产毛片aaaaa无费看| 国产情人综合久久777777| 日韩亚洲欧美成人一区| 一本色道久久综合亚洲精品按摩| 国产一区中文字幕| 麻豆精品一区二区综合av| 亚洲一区自拍偷拍| 1区2区3区精品视频| 国产婷婷一区二区| 精品国产伦一区二区三区观看方式| 欧美日本一区二区三区| 91久久久免费一区二区| 色综合久久中文字幕综合网 | 国产精品夜夜嗨| 激情综合一区二区三区| 青娱乐精品在线视频| 91性感美女视频| eeuss鲁片一区二区三区在线看| 日韩一本二本av| 精品国产免费人成电影在线观看四季 | 国产精品免费网站在线观看| 久久久久久久网| 久久久精品tv| 中文字幕+乱码+中文字幕一区| 亚洲国产精品精华液ab| 国产精品萝li| 一区二区激情小说| 青娱乐精品在线视频| 国内一区二区视频| av中文一区二区三区| 91久久线看在观草草青青| 欧美三级三级三级爽爽爽| 欧美日韩夫妻久久| 久久蜜桃av一区二区天堂| 中文字幕欧美激情一区| 亚洲一区在线播放| 蜜桃视频一区二区三区在线观看| 免费成人在线播放| 成人性生交大片免费看视频在线 | √…a在线天堂一区| 亚洲福利电影网| 国产精一区二区三区| 91免费看`日韩一区二区| 69堂国产成人免费视频| 国产三级精品在线| 亚洲理论在线观看| 精品一区二区在线播放| av成人老司机| 日韩电影在线一区| 成人激情开心网| 日韩一卡二卡三卡国产欧美| 国产精品白丝在线| 免费一级片91| 色网站国产精品| 国产亚洲一区二区在线观看| 日韩国产高清影视| 色噜噜夜夜夜综合网| 中文字幕欧美区| 精品一区二区三区免费视频| 欧美群妇大交群的观看方式| 亚洲少妇中出一区| 精品一二线国产| 欧美精品久久天天躁| 一区二区三区鲁丝不卡| 大白屁股一区二区视频| 精品国产一二三| 日本三级亚洲精品| 欧美福利电影网| 亚洲综合在线视频| 色久优优欧美色久优优| 中文字幕日韩欧美一区二区三区| 国产91清纯白嫩初高中在线观看 | 亚洲精品一线二线三线无人区| 亚洲h精品动漫在线观看| 欧美亚洲图片小说| 一区二区三区四区高清精品免费观看 | 91久久精品网| 一区二区三区日本| 在线中文字幕不卡| 亚洲国产乱码最新视频 | 51精品视频一区二区三区| 亚洲第一搞黄网站| 欧美日韩国产大片| 日韩国产欧美在线视频| 欧美大白屁股肥臀xxxxxx| 精品亚洲porn| 中文字幕一区视频| 欧洲精品在线观看| 日本欧美肥老太交大片| 精品福利一区二区三区免费视频| 精品在线播放午夜| 亚洲国产精品国自产拍av| 色婷婷久久一区二区三区麻豆| 性久久久久久久久| 欧美成人一区二区三区在线观看 | 久久国产福利国产秒拍| 国产日韩欧美高清| 色婷婷精品久久二区二区蜜臂av| 亚洲国产日韩a在线播放| 欧美成人精品3d动漫h| 成人黄色免费短视频| 亚洲国产视频在线| 久久尤物电影视频在线观看| 色综合中文综合网| 蜜桃精品视频在线| 《视频一区视频二区| 欧美一区二区免费视频| caoporn国产一区二区| 日韩精品免费专区| 综合久久久久综合| 精品剧情v国产在线观看在线| 色综合天天综合色综合av| 蜜臀91精品一区二区三区| 一区二区三区在线视频观看| 久久一夜天堂av一区二区三区| 欧美亚日韩国产aⅴ精品中极品| 国产一区二区三区精品欧美日韩一区二区三区| 国产精品大尺度| 久久先锋影音av| 在线成人午夜影院| 欧洲一区二区av| 在线视频综合导航| eeuss鲁一区二区三区| 国产精品中文有码| 激情综合网av| 美女视频黄a大片欧美| 亚洲国产成人av好男人在线观看| 国产精品久久久久婷婷| 日本一区二区三区电影| 国产午夜亚洲精品羞羞网站| 亚洲精品一区二区三区蜜桃下载| 在线播放国产精品二区一二区四区| 色久优优欧美色久优优| 成人国产精品免费观看动漫| 亚洲成a天堂v人片| 国产精品成人免费| 欧美人与禽zozo性伦| 678五月天丁香亚洲综合网| 精品国免费一区二区三区| 国产精品三级av| 五月天丁香久久| www.欧美日韩| 欧美一区二区三区在线观看| 国产精品三级视频| 日韩精品乱码免费| 91原创在线视频| 久久亚洲精品小早川怜子| 亚洲午夜国产一区99re久久| 国产九色sp调教91| 91精品久久久久久久91蜜桃| 一色屋精品亚洲香蕉网站| 天天操天天色综合| 高清成人免费视频| 在线播放一区二区三区| 国产精品欧美一级免费| 日韩高清不卡一区|