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

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

?? d_stree.h

?? 自定義的二叉搜索樹的頭文件
?? H
?? 第 1 頁 / 共 2 頁
字號:
	// t is current node in traversal, parent the previous node
	stnode<T> *t = root, *parent = NULL, *newNode;

	// terminate on on empty subtree
	while(t != NULL)
	{
		// update the parent pointer. then go left or right
		parent = t;
		// if a match occurs, return a pair whose iterator
		// component points at item in the tree and whose
		// bool component is false
		if (item == t->nodeValue)
			return pair<iterator, bool> (iterator(t, this), false);
		else if (item < t->nodeValue)
			t = t->left;
		else 
			t = t->right;
	}
    
	// create the new leaf node
	newNode = getSTNode(item,NULL,NULL,parent);

	// if parent is NULL, insert as root node
	if (parent == NULL)
		root = newNode;
	else if (item < parent->nodeValue)                   
		// insert as left child        
		parent->left = newNode;  
	else
		// insert as right child     
		parent->right = newNode;
  
	// increment size
	treeSize++;

	// return an pair whose iterator component points at
	// the new node and whose bool component is true
	return pair<iterator, bool> (iterator(newNode, this), true);
}

template <typename T>
void stree<T>::erase(iterator pos)
{
	// dNodePtr = pointer to node D that is deleted
	// pNodePtr = pointer to parent P of node D
	// rNodePtr = pointer to node R that replaces D
	stnode<T> *dNodePtr = pos.nodePtr, *pNodePtr, *rNodePtr;

	if (treeSize == 0)
 		throw
			underflowError("stree erase(): tree is empty");

	if (dNodePtr == NULL)
 		throw
			referenceError("stree erase(): invalid iterator");

	// assign pNodePtr the address of P
	pNodePtr = dNodePtr->parent;

	// If D has a NULL pointer, the
	// replacement node is the other child
	if (dNodePtr->left == NULL || dNodePtr->right == NULL)
	{
		if (dNodePtr->right == NULL)
			rNodePtr = dNodePtr->left;
		else
			rNodePtr = dNodePtr->right;

		if (rNodePtr != NULL)
			// the parent of R is now the parent of D
			rNodePtr->parent = pNodePtr;
	}
	// both pointers of dNodePtr are non-NULL.
	else
	{
		// find and unlink replacement node for D.
		// starting at the right child of node D,
		// find the node whose value is the smallest of all
		// nodes whose values are greater than the value in D.
		// unlink the node from the tree.
  
		// pOfRNodePtr = pointer to parent of replacement node
		stnode<T> *pOfRNodePtr = dNodePtr;

		// first possible replacement is right child of D
		rNodePtr = dNodePtr->right;

		// descend down left subtree of the right child of D,
		// keeping a record of current node and its parent.
		// when we stop, we have found the replacement
		while(rNodePtr->left != NULL)
		{
			pOfRNodePtr = rNodePtr;
			rNodePtr = rNodePtr->left;
		}
  
		if (pOfRNodePtr == dNodePtr)
		{
			// right child of deleted node is the replacement.
			// assign left subtree of D to left subtree of R
			rNodePtr->left = dNodePtr->left;
			// assign the parent of D as the parent of R
			rNodePtr->parent = pNodePtr;
			// assign the left child of D to have parent R
			dNodePtr->left->parent = rNodePtr;
		}
		else
		{
			// we moved at least one node down a left branch
			// of the right child of D. unlink R from tree by
			// assigning its right subtree as the left child of
			// the parent of R
			pOfRNodePtr->left = rNodePtr->right;

			// the parent of the right child of R is the
			// parent of R
			if (rNodePtr->right != NULL)
				rNodePtr->right->parent = pOfRNodePtr;

			// put replacement node in place of dNodePtr
			// assign children of R to be those of D
			rNodePtr->left = dNodePtr->left;
			rNodePtr->right = dNodePtr->right;
			// assign the parent of R to be the parent of D
			rNodePtr->parent = pNodePtr;
			// assign the parent pointer in the children
			// of R to point at R
			rNodePtr->left->parent = rNodePtr;
			rNodePtr->right->parent = rNodePtr;
		}
	}

	// complete the link to the parent node.

	// deleting the root node. assign new root
	if (pNodePtr == NULL)
		root = rNodePtr;
	// attach R to the correct branch of P
	else if (dNodePtr->nodeValue < pNodePtr->nodeValue)
		pNodePtr->left = rNodePtr;
	else
		pNodePtr->right = rNodePtr;
  
	// delete the node from memory and decrement tree size
	delete dNodePtr;
	treeSize--;
}

template <typename T>
int stree<T>::erase(const T& item)
{
	int numberErased = 1;
	// search tree for item
	stnode<T> *p  = findNode(item);

	// if item found, delete the node
	if (p != NULL)
		erase(iterator(p,this));
	else
		numberErased = 0;

	return numberErased;
}

template <typename T>
void stree<T>::erase(iterator first, iterator last)
{
	if (treeSize == 0)
 		throw
			underflowError("stree erase(): tree is empty");

	iterator p = first;

	if (first == begin() && last == end())
	{
		// we are asked to erase the entire tree.
		// erase the tree nodes from memory
		deleteTree(root);

		// tree is emtpy
		root = NULL;
		treeSize = 0;
	}
	else
		// erase each item in a subrange of the tree
		while (p != last)
			erase(p++);
}

template <typename T>
stree<T>::iterator stree<T>::begin()
{
	stnode<T> *curr = root;

	// if the tree is not empty, the first node
	// inorder is the farthest node left from root
	if (curr != NULL)
		while (curr->left != NULL)
			curr = curr->left;

	// build return value using private constructor
	return iterator(curr, this);
}

template <typename T>
stree<T>::const_iterator stree<T>::begin() const
{
	const stnode<T> *curr = root;

	// if the tree is not empty, the first node
	// inorder is the farthest node left from root
	if (curr != NULL)
		while (curr->left != NULL)
			curr = curr->left;

	// build return value using private constructor
	return const_iterator(curr, this);
}

template <typename T>
stree<T>::iterator stree<T>::end()
{
	// end indicated by an iterator with NULL stnode pointer
	return iterator(NULL, this);
}

template <typename T>
stree<T>::const_iterator stree<T>::end() const
{
	// end indicated by an iterator with NULL stnode pointer
	return const_iterator(NULL, this);
}

// recursive inorder scan used to build the shadow tree
template <typename T>
tnodeShadow *stree<T>::buildShadowTree(stnode<T> *t, int level, int& column)
{
	// pointer to new shadow tree node
	tnodeShadow *newNode = NULL;
	// text and ostr used to perform format conversion
	char text[80];
	ostrstream ostr(text,80);

	if (t != NULL)
	{
		// create the new shadow tree node
		newNode = new tnodeShadow;

		// allocate node for left child at next level in tree; attach node
		tnodeShadow *newLeft = buildShadowTree(t->left, level+1, column);
		newNode->left = newLeft;

		// initialize data members of the new node
		ostr << t->nodeValue << ends;	// format conversion
		newNode->nodeValueStr = text;
		newNode->level = level;
		newNode->column = column;

		// update column to next cell in the table
		column++;

		// allocate node for right child at next level in tree; attach node
		tnodeShadow *newRight = buildShadowTree(t->right, level+1, column);
		newNode->right = newRight;
	}

	return newNode;
}

template <typename T>
void stree<T>::displayTree(int maxCharacters)
{
	string label;
	int level = 0, column = 0;
	int colWidth = maxCharacters + 1;
	// 
	int currLevel = 0, currCol = 0;

	if (treeSize == 0)
		return;

	// build the shadow tree
	tnodeShadow *shadowRoot = buildShadowTree(root, level, column);

	// use during the level order scan of the shadow tree
	tnodeShadow *currNode;

   // store siblings of each tnodeShadow object in a queue so that
	// they are visited in order at the next level of the tree
   queue<tnodeShadow *> q;

   // insert the root in the queue and set current level to 0
   q.push(shadowRoot);
   
   // continue the iterative process until the queue is empty
   while(!q.empty())
   {
      // delete front node from queue and make it the current node
      currNode = q.front();
		q.pop();

		// if level changes, output a newline
		if (currNode->level > currLevel)
		{
			currLevel = currNode->level;
			currCol = 0;
			cout << endl;
		}

		// if a left child exists, insert the child in the queue
      if(currNode->left != NULL)
			q.push(currNode->left);

		// if a right child exists, insert the child in the queue
      if(currNode->right != NULL)
			q.push(currNode->right);

		// output formatted node label
		if (currNode->column > currCol)
		{
			cout << setw((currNode->column-currCol)*colWidth) << " ";
			currCol = currNode->column;
		}
		cout << setw(colWidth) << currNode->nodeValueStr;
		currCol++;
   }
	cout << endl;

	// delete the shadow tree
	deleteShadowTree(shadowRoot);
}

template <typename T>
void stree<T>::deleteShadowTree(tnodeShadow *t)
{
	// if current root node is not NULL, delete its left subtree,
	// its right subtree and then the node itself
	if (t != NULL)
	{
		deleteShadowTree(t->left);
		deleteShadowTree(t->right);
		delete t;
	}
}

#endif  // BINARY_SEARCH_TREE_CLASS

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91麻豆国产在线观看| 欧洲在线/亚洲| 亚洲成人资源在线| 国产性做久久久久久| 欧美精品久久99| 91亚洲国产成人精品一区二三 | 中文字幕乱码亚洲精品一区| 欧美视频中文字幕| 成人av先锋影音| 黄色小说综合网站| 日韩精品国产欧美| 亚洲一区在线视频| 亚洲丝袜另类动漫二区| 久久奇米777| 日韩欧美你懂的| 欧美人体做爰大胆视频| 99国产精品久久久| 国产精品亚洲一区二区三区妖精 | 久久久欧美精品sm网站| 欧美日韩在线三区| 91老司机福利 在线| 成人午夜激情在线| 国产精品一卡二卡| 国产一区二区网址| 久久国产生活片100| 日韩av网站在线观看| 亚洲专区一二三| 一区二区三区在线视频观看58 | 日韩中文字幕av电影| 亚洲自拍偷拍欧美| 亚洲午夜激情av| 一区二区三区日韩欧美精品| 综合激情网...| 国产精品色在线观看| 久久久久高清精品| 久久久久久久国产精品影院| 精品久久久久久综合日本欧美| 欧美理论在线播放| 在线不卡免费av| 91精品国产91热久久久做人人| 欧美日韩一区小说| 制服.丝袜.亚洲.中文.综合| 欧美久久一二三四区| 欧美日韩大陆一区二区| 欧美日韩国产大片| 日韩一区二区免费在线电影| 91精品国产综合久久福利软件 | 欧美精品精品一区| 制服丝袜av成人在线看| 日韩一级高清毛片| 久久久青草青青国产亚洲免观| 久久久国产精品午夜一区ai换脸| 久久婷婷久久一区二区三区| 2014亚洲片线观看视频免费| 久久精品视频一区二区三区| 中文字幕免费不卡| 亚洲欧美区自拍先锋| 亚洲电影一区二区三区| 日韩av一级片| 丰满放荡岳乱妇91ww| 91网站最新地址| 欧美精品三级日韩久久| 欧美精品一区二区三区高清aⅴ | 国产日产欧美一区二区视频| 中国色在线观看另类| 一级精品视频在线观看宜春院| 午夜a成v人精品| 国产精品一区二区x88av| 99在线精品视频| 欧美三级中文字幕在线观看| 日韩欧美一卡二卡| 国产精品电影院| 亚洲成人三级小说| 国产乱子伦视频一区二区三区 | 欧美电影免费观看高清完整版在线观看| 久久一区二区三区四区| 亚洲欧美综合在线精品| 亚洲成人av中文| 国产精品一卡二卡| 欧美日韩亚洲综合一区二区三区| 欧美电影精品一区二区| 国产精品黄色在线观看| 日韩在线a电影| 成人免费毛片app| 欧美日韩国产三级| 国产精品午夜春色av| 午夜精品久久一牛影视| 成人性生交大片免费看在线播放| 欧美色偷偷大香| 国产精品免费人成网站| 麻豆精品在线观看| 91精品办公室少妇高潮对白| 精品欧美黑人一区二区三区| 亚洲精品国产第一综合99久久| 男人的天堂久久精品| 91麻豆蜜桃一区二区三区| 精品毛片乱码1区2区3区| 亚洲另类春色校园小说| 国产成人av电影在线播放| 欧美日韩国产片| 亚洲男帅同性gay1069| 国模无码大尺度一区二区三区| 色婷婷久久99综合精品jk白丝| 久久亚洲一区二区三区四区| 亚洲成年人影院| 日本丰满少妇一区二区三区| 国产拍揄自揄精品视频麻豆| 日本特黄久久久高潮| 欧美性videosxxxxx| 中文字幕中文在线不卡住| 久久国产视频网| 欧美一区二区不卡视频| 亚洲国产日韩a在线播放| 99免费精品视频| 中文字幕av在线一区二区三区| 久久精品国产99国产精品| 欧美二区在线观看| 亚洲国产综合在线| 在线观看网站黄不卡| 亚洲色图20p| av亚洲精华国产精华| 国产欧美日韩另类一区| 精品一区二区国语对白| 欧美一区二区三区在线| 亚洲成人精品在线观看| 欧美日韩一区二区在线观看视频| 综合久久综合久久| eeuss影院一区二区三区| 国产日韩欧美在线一区| 国产成人精品免费网站| 久久久三级国产网站| 国产精品综合久久| 久久久一区二区三区捆绑**| 九一久久久久久| 久久久久久综合| 国产成人8x视频一区二区| 久久一二三国产| 成人中文字幕在线| 国产精品视频在线看| 成人app在线观看| 日韩一区在线看| 日本道精品一区二区三区| 自拍偷在线精品自拍偷无码专区| 91在线视频网址| 亚洲综合免费观看高清在线观看| 欧美最猛性xxxxx直播| 亚洲va欧美va国产va天堂影院| 欧美日韩在线一区二区| 美腿丝袜在线亚洲一区| 欧美成人精品高清在线播放| 久久av资源网| 日本一区二区三区四区| heyzo一本久久综合| 亚洲自拍都市欧美小说| 91精品国产乱码久久蜜臀| 久久精品72免费观看| 欧美高清在线一区| 一本久久综合亚洲鲁鲁五月天| 亚洲一卡二卡三卡四卡无卡久久| 欧美日韩三级一区二区| 久久不见久久见免费视频1| 久久免费午夜影院| 一本久久a久久精品亚洲| 亚洲午夜精品一区二区三区他趣| 91精品国产色综合久久不卡蜜臀 | 亚洲欧美日韩电影| 欧美高清视频www夜色资源网| 另类小说欧美激情| 国产精品国产成人国产三级| 在线这里只有精品| 久久超碰97人人做人人爱| 亚洲欧洲日韩在线| 欧美二区乱c少妇| 成人深夜在线观看| 天堂一区二区在线| 久久精品日韩一区二区三区| 在线视频中文字幕一区二区| 蜜桃一区二区三区在线| 国产精品久久久久久久久快鸭| 在线欧美小视频| 国产一区二区视频在线| 亚洲黄色性网站| 久久看人人爽人人| 欧美日韩国产经典色站一区二区三区 | 激情文学综合插| 一区二区三区在线观看欧美| 欧美一区二区三区白人| 99久久精品一区| 麻豆传媒一区二区三区| 亚洲乱码国产乱码精品精的特点| 777色狠狠一区二区三区| www.亚洲免费av| 久久99久久精品| 一区二区三区色| 欧美精彩视频一区二区三区| 欧美猛男gaygay网站| 91网上在线视频| 福利电影一区二区三区| 日韩精品五月天| 亚洲精品欧美专区|