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

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

?? avltreenode.java.bak

?? 數(shù)據(jù)結構中的AVL TREE的實現(xiàn)
?? BAK
字號:
/**
 *	@ AVLTreeNode.java
 *	@ Designed by BySelf
 */

import java.util.Stack;
import java.lang.Math;
/**
 *	AVLTreeNode
 *		Tree node used to implemennt the AVLTree.
 *	NOTE:
 *		1. The node has a unique value, that will used to decide its in tree position
 *		2. You should implement rotateLeft and rotateRight for further implementation
 *		   did in AVLTree.
 */
class AVLTreeNode 
{
	/**
	 *	Constructor
	 *		initialize all the node fields values.
	 */
	public AVLTreeNode(int value)
	{
		subTreeHeight = 0;		// initialize to be zero
		leftChild = null;
		rightChild = null;
		parent = null;
		this.value = value;
	}

	/**
	 *	public int balanceValue
	 *		balance value of this TreeNode, initialized to be 0
	 *		balanceValue = leftChild.getSubTreeHeight() - rightChild.getSubTreeHeight().
	 *	NOTE:
	 *		You can use this field and make your AVLTree insert and delete a little 
	 *		easier, but you can also omit it.
	 */
	public int balanceValue;


	/**
	 *	private int value
	 *		Decide the value of this node, which is used to decide the 
	 *		insert position of this node.
	 */
	private int value;

	/**
	 *	public int getValue()
	 *		Get the value of this node.
	 *	NOTE: 
	 *		leftChild.value < this.value < rightChild.value
	 */
	public int getValue()
	{
		return value;
	}

	/**
	 *	private int subTreeHeight
	 *		The balance value of this AVLTreeNode
	 *	NOTE:
	 *		1. initialized to be zero
	 *		2. value = the height of its subtree, i will use this feature
	 *		   to test the correctness of your subTreeHeight
	 *		3. whenever rotate or do something change the height of subtree
	 *		   remember to change its value
	 */
	private int subTreeHeight;

	/**
	 *	public int setValue(int newValue)
	 *		Set this.subTreeHeight to be newValue.
	 *		Return old subTreeHeight;
	 */
	public int setSubTreeHeight(int newValue)
	{
		int oldValue = subTreeHeight;
		subTreeHeight = newValue;
		return oldValue;
	}

	/**
	 *	public int getValue()
	 *		Get current node's subTreeHeight.
	 *		Return this.subTreeHeight.
	 */
	public int getSubTreeHeight()
	{
		return subTreeHeight;
	}

	/**
	 *	private AVLTreeNode leftChild
	 *		The left child of current tree node. It is true that 
	 *		child.subTreeHeight <= this.subTreeHeight-1.
	 */
	private AVLTreeNode leftChild;

	/**
	 *	public AVLTreeNode setLeftChild(AVLTreeNode leftChild)
	 *		Set the left child node.
	 *		Return old child.
	 */
	public AVLTreeNode setLeftChild(AVLTreeNode leftChild)
	{
		AVLTreeNode oldChild = this.leftChild;
		this.leftChild = leftChild;
		return oldChild;
	}

	/**
	 *	public AVLTreeNode getLeftChild()
	 *		Get the left child node of this.
	 */
	public AVLTreeNode getLeftChild()
	{
		return leftChild;
	}

	/**
	 *	private AVLTreeNode rightChild
	 *		The right child of current tree node. It is true that 
	 *		child.subTreeHeight <= this.subTreeHeight-1.
	 *  NOTE: 
	 *      this.subTreeHeight = max(rightChild.subTreeHeight+1, 
	 *								leftChild.subTreeHeight+1).
	 */	
	private AVLTreeNode rightChild;

	/**
	 *	public AVLTreeNode setRightChild(AVLTreeNode rightChild)
	 *		Set the right child node.
	 *		Return old child.
	 */
	public AVLTreeNode setRightChild(AVLTreeNode rightChild)
	{
		AVLTreeNode oldChild = this.rightChild;
		this.rightChild = rightChild;
		return oldChild;
	}

	/**
	 *	public AVLTreeNode getRightChild()
	 *		Get the right child node of this.
	 */
	public AVLTreeNode getRightChild()
	{
		return rightChild;
	}

	/**
	 *	private AVLTreeNode parent
	 *		The parent node of this tree node, it may be useful when
	 *		doing rotating.
	 */
	private AVLTreeNode parent;

	/**
	 *	public AVLTreeNode setParent(AVLTreeNode parent)
	 *		Set the parent node.
	 *		Return old parent.
	 */
	public AVLTreeNode setParent(AVLTreeNode parent)
	{
		AVLTreeNode oldParent = this.parent;
		this.parent = parent;
		return oldParent;
	}

	/**
	 *	public AVLTreeNode getParent()
	 *		Get the parent node of this.
	 */
	public AVLTreeNode getParent()
	{
		return parent;
	}

	public void setBalance(AVLTreeNode node)
	{
		if ( node == null)
			return;
		if ( node.leftChild == null && node.rightChild == null ) 
			node.balanceValue = 0;
		else if ( node.leftChild == null )
			node.balanceValue = -1;
		else if ( node.rightChild == null )
			node.balanceValue = 1;
		else
		{
			if ( node.leftChild.subTreeHeight == node.rightChild.subTreeHeight )
				node.balanceValue = 0;
			else if ( node.leftChild.subTreeHeight < node.rightChild.subTreeHeight )
				node.balanceValue = -1;
			else
				node.balanceValue = 1;
		}
	}

	public void setSubHeight(AVLTreeNode node)
	{
		if ( node == null)
			return;
		if ( node.leftChild == null && node.rightChild == null )
			node.setSubTreeHeight(0);
		else if ( node.leftChild == null )
			node.setSubTreeHeight( node.rightChild.subTreeHeight + 1 );
		else if ( node.rightChild == null )
			node.setSubTreeHeight( node.leftChild.subTreeHeight + 1 );
		else
			node.setSubTreeHeight( Math.max( node.leftChild.subTreeHeight + 1, node.rightChild.subTreeHeight + 1 ) );
	}
	/**
	 *	public AVLTreeNode rotateLeft();
	 *		Rotate current AVLTreeNode left, then return the parent node
	 *	NOTE:
	 *		Do not forget to change balance value when doing rotate
	 */
	public AVLTreeNode rotateLeft()
	{
		// fill your implementation code here
		// you can change the return value as you like
		// remember that you cannot change the _value_ field
		AVLTreeNode temp = this.parent;
		AVLTreeNode node1 = this;
		AVLTreeNode node2 = this.leftChild;
		
		if ( temp == null )
			return null;

		node1.setParent(temp.parent);
		if ( temp.parent != null )
		{
			if ( temp.value < temp.parent.value )
				temp.parent.setLeftChild(node1);
			else
				temp.parent.setRightChild(node1);
		}

		node1.setLeftChild(temp);
		temp.setParent(node1);
		
		temp.setRightChild(node2);
		if ( node2 != null )
			node2.setParent(temp);

		setSubHeight(temp);
		setSubHeight(node1);
		setSubHeight(node2);
		setBalance(temp);
		setBalance(node1);
System.out.println(node1.value+" "+node1.subTreeHeight);/////////////////////////////////
		return node1;
	}

	/**
	 *	public AVLTreeNode rotateRight();
	 *		Rotate current AVLTreeNode right, then return the parent node
	 *	NOTE:
	 *		Do not forget to change balance value when doing rotate
	 */
	public AVLTreeNode rotateRight()
	{
		// fill your implementation code here
		// you can change the return value as you like
		// remember that you cannot change the _value_ field
		AVLTreeNode temp = this;
		AVLTreeNode node1 = this.leftChild;
		AVLTreeNode node2 = this.leftChild.rightChild;

		if ( node1 == null )
			return null;

		node1.setParent(this.parent);
		if ( this.parent != null )
		{
			if ( this.value < this.parent.value )
				this.parent.setLeftChild(node1);
			else
				this.parent.setRightChild(node1);
		}

		node1.setRightChild(temp);
		temp.setParent(node1);

		temp.setLeftChild(node2);
		if ( node2 != null )
			node2.setParent(temp);

		setSubHeight(temp);
		setSubHeight(node1);
		setSubHeight(node2);
		setBalance(temp);
		setBalance(node1);
System.out.println(node1.subTreeHeight);//////////////////////////////
		return node1;
	}

	/**
	 *	public void inOrder(AVLTreeNode node)
	 *		Do inOrder walk in this subnode.
	 */
	public static void inOrder(AVLTreeNode node)
	{
		Stack stack=new Stack();
		stack.push(node);
		while(!stack.empty())
		{
			Object obj = stack.pop();
			if(obj instanceof AVLTreeNode)
			{
				AVLTreeNode curNode = (AVLTreeNode)obj;
				if (curNode.rightChild != null)
					stack.push(curNode.rightChild);
				stack.push(new Integer(curNode.value));
				if (curNode.leftChild != null)
					stack.push(curNode.leftChild);
			}
			else
			{
				System.out.print("[" + obj + "] ");
			}
		}
	}

	/**
	 *	public static void main(String[] args)
	 *		Do test.
	 */
	public static void main(String[] args) 
	{
		System.out.println("============ Testing Rotate ============");
		System.out.println(">>>> In order walk should always be:");
		System.out.println("[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]");
		System.out.println();
//	init tree: 
//                           [15]
//                         /       \
//                    [11]           [17]
//                  /      \        /    \
//              [7]        [13]   [16]  [18]
//            /     \     /    \   
//         [3]      [9] [12]  [14]
//        /   \     / \  
//      [1]   [5] [8] [10]
//      / \   / \
//    [0][2][4][6]

		AVLTreeNode[] node = new AVLTreeNode[19];
		for (int i = 0; i < 19; i++)
		{
			node[i] = new AVLTreeNode(i);
		}
		node[0].parent = node[1];
		node[2].parent = node[1];
		node[1].leftChild = node[0];
		node[1].rightChild = node[2];

		node[4].parent = node[5];
		node[6].parent = node[5];
		node[5].leftChild = node[4];
		node[5].rightChild = node[6];

		node[1].parent = node[3];
		node[5].parent = node[3];
		node[3].leftChild = node[1];
		node[3].rightChild = node[5];

		node[8].parent = node[9];
		node[10].parent = node[9];
		node[9].leftChild = node[8];
		node[9].rightChild = node[10];

		node[3].parent = node[7];
		node[9].parent = node[7];
		node[7].leftChild = node[3];
		node[7].rightChild = node[9];

		node[12].parent = node[13];
		node[14].parent = node[13];
		node[13].leftChild = node[12];
		node[13].rightChild = node[14];

		node[7].parent = node[11];
		node[13].parent = node[11];
		node[11].leftChild = node[7];
		node[11].rightChild = node[13];

		node[16].parent = node[17];
		node[18].parent = node[17];
		node[17].leftChild = node[16];
		node[17].rightChild = node[18];

		node[11].parent = node[15];
		node[17].parent = node[15];
		node[15].leftChild = node[11];
		node[15].rightChild = node[17];

		System.out.println("First inwalk after init:");
		AVLTreeNode.inOrder(node[15]);
		System.out.println();
		System.out.println();

// After node[11].rotateRight:
//                         [15]
//                      /         \
//                [7]                [17]
//              /     \             /    \
//         [3]          [11]      [16]  [18]
//        /   \        /    \
//      [1]   [5]   [9]      [13]
//      / \   / \   / \     /    \     
//    [0][2][4][6][8] [10][12]  [14]

		System.out.println(">>>> Rotating right:");
		AVLTreeNode a7 = node[11].rotateRight();
		System.out.println("Rotating finished");
		System.out.println("Check subtree root node current subtree root node should be [ 7 ]:");
		System.out.println("> The result subtree root is : [ " + a7.getValue() + " ]");
		System.out.println("> Parent of node [ 7 ] should be [ 15 ] : [ " 
				+ node[7].parent.getValue() + " ]");
		System.out.println("> Left child of node [ 7 ] should be [ 3 ] : [ " 
				+ node[7].leftChild.getValue() + " ]");
		System.out.println("> Right child of node [ 7 ] should be [ 11 ] : [ " 
				+ node[7].rightChild.getValue() + " ]");
		System.out.println("> Parent of node [ 9 ] should be [ 11 ] : [ " 
				+ node[9].parent.getValue() + " ]");
		System.out.println("> Parent of node [ 11 ] should be [ 7 ] : [ " 
				+ node[11].parent.getValue() + " ]");
		System.out.println("> Left child of node [ 11 ] should be [ 9 ] : [ " 
				+ node[11].leftChild.getValue() + " ]");
		System.out.println("> Left child of node [ 15 ] should be [ 7 ] : [ " 
				+ node[15].leftChild.getValue() + " ]");

		System.out.println();

		System.out.println("Second inwalk after rotate right:");
		AVLTreeNode.inOrder(node[15]);
		System.out.println();
		System.out.println();

// After node[11].rotateLeft:
//                           [15]
//                         /       \
//                    [11]           [17]
//                  /      \        /    \
//              [7]        [13]   [16]  [18]
//            /     \     /    \   
//         [3]      [9] [12]  [14]
//        /   \     / \  
//      [1]   [5] [8] [10]
//      / \   / \
//    [0][2][4][6]
		System.out.println(">>>> Rotating left:");
		AVLTreeNode a11 = node[11].rotateLeft();
		System.out.println("Rotating finished");
		System.out.println("Check subtree root node current subtree root node should be [ 11 ]:");
		System.out.println("> The result subtree root is : [ " + a11.getValue() + " ]");
		System.out.println("> Parent of node [ 7 ] should be [ 11 ] : [ " 
				+ node[7].parent.getValue() + " ]");
		System.out.println("> Left child of node [ 7 ] should be [ 3 ] : [ " 
				+ node[7].leftChild.getValue() + " ]");
		System.out.println("> Right child of node [ 7 ] should be [ 9 ] : [ " 
				+ node[7].rightChild.getValue() + " ]");
		System.out.println("> Parent of node [ 9 ] should be [ 7 ] : [ " 
				+ node[9].parent.getValue() + " ]");
		System.out.println("> Parent of node [ 11 ] should be [ 15 ] : [ " 
				+ node[11].parent.getValue() + " ]");
		System.out.println("> Left child of node [ 11 ] should be [ 7 ] : [ " 
				+ node[11].leftChild.getValue() + " ]");
		System.out.println("> Left child of node [ 15 ] should be [ 11 ] : [ " 
				+ node[15].leftChild.getValue() + " ]");

		System.out.println();

		System.out.println("Third inwalk after rotate left:");
		AVLTreeNode.inOrder(node[15]);
		System.out.println();
		System.out.println();
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产欧美一区二区精品婷婷| 亚洲国产日韩精品| 一区二区三区在线看| 免费高清在线一区| 99久久免费精品| 欧美一级在线观看| 日韩理论片网站| 国产999精品久久久久久绿帽| 欧美视频在线播放| 亚洲视频综合在线| 成人开心网精品视频| 欧美变态tickling挠脚心| 有码一区二区三区| av在线不卡免费看| 中文字幕欧美激情| 国产真实乱子伦精品视频| 欧美妇女性影城| 夜夜嗨av一区二区三区网页| 成人性色生活片| 久久久99精品免费观看不卡| 免费欧美在线视频| 欧美日韩国产乱码电影| 亚洲国产精品一区二区久久| 91网站最新网址| 国产精品少妇自拍| 国产成人免费在线| 久久久噜噜噜久久中文字幕色伊伊 | 欧美日韩高清影院| 亚洲黄色小视频| 欧洲一区在线电影| 亚洲精品综合在线| 在线免费精品视频| 亚洲男人的天堂av| 欧洲精品一区二区| 亚洲bt欧美bt精品777| 欧美午夜在线观看| 日本一区中文字幕| 久久综合色天天久久综合图片| 免费高清不卡av| 2014亚洲片线观看视频免费| 国产精一品亚洲二区在线视频| 久久精品一区四区| 本田岬高潮一区二区三区| 欧美激情一区在线| 99久久99久久免费精品蜜臀| 亚洲人亚洲人成电影网站色| 欧美性生交片4| 三级久久三级久久久| 日韩一二三四区| 九九九精品视频| 国产欧美日韩中文久久| 91色乱码一区二区三区| 亚洲一区二区三区在线看| 欧美日韩国产一区| 九色综合狠狠综合久久| 国产精品亲子伦对白| 欧美在线免费视屏| 免费观看一级欧美片| 中文字幕av一区 二区| 色综合久久88色综合天天| 婷婷久久综合九色国产成人| 精品国产乱子伦一区| 成人综合婷婷国产精品久久免费| 亚洲视频免费在线| 91精品婷婷国产综合久久| 国精产品一区一区三区mba桃花 | 久久久久99精品国产片| 99九九99九九九视频精品| 亚洲国产成人精品视频| 精品欧美久久久| 99re6这里只有精品视频在线观看| 亚洲永久精品国产| 久久综合狠狠综合久久激情| 91免费版在线| 另类小说一区二区三区| 亚洲色大成网站www久久九九| 欧美一级黄色大片| 91同城在线观看| 久久成人羞羞网站| 亚洲v精品v日韩v欧美v专区| 国产精品免费视频观看| 日韩女优av电影在线观看| 色噜噜狠狠色综合中国| 高清国产午夜精品久久久久久| 亚洲成人综合网站| 成人免费视频在线观看| 欧美va亚洲va| 欧美日韩五月天| 北条麻妃一区二区三区| 国产一区二区三区四区在线观看| 亚洲午夜视频在线观看| 成人免费一区二区三区在线观看| 欧美精品一区二区三区四区| 欧美性猛交xxxx乱大交退制版| 粉嫩久久99精品久久久久久夜| 日本午夜精品一区二区三区电影| 亚洲精品久久久蜜桃| 国产精品午夜在线观看| 久久奇米777| 欧美va亚洲va香蕉在线| 日韩欧美激情四射| 欧美一区三区四区| 在线观看不卡一区| 色天天综合色天天久久| 99这里只有久久精品视频| 国产99久久久精品| 国产麻豆成人精品| 国产精品资源网| 精品一区二区av| 狠狠色丁香婷综合久久| 久久精品国产久精国产爱| 另类专区欧美蜜桃臀第一页| 日韩成人精品在线观看| 日韩高清在线不卡| 日韩国产精品久久久久久亚洲| 亚洲成人你懂的| 婷婷久久综合九色综合伊人色| 婷婷六月综合网| 免费人成黄页网站在线一区二区| 日韩二区三区在线观看| 久久精品国产一区二区三 | heyzo一本久久综合| 成人一级片在线观看| 国产成人自拍高清视频在线免费播放| 国产一区二区不卡| 成人免费视频app| 色综合天天综合狠狠| 91福利在线观看| 欧美老年两性高潮| 欧美成人三级在线| 国产欧美日本一区二区三区| 日本一区二区三级电影在线观看 | 波多野结衣在线aⅴ中文字幕不卡| 粉嫩一区二区三区性色av| aaa欧美色吧激情视频| 欧洲一区二区三区在线| 欧美一区二区三区视频在线| 26uuu久久天堂性欧美| 国产精品福利一区| 夜夜嗨av一区二区三区四季av| 日本vs亚洲vs韩国一区三区二区| 激情国产一区二区| aaa国产一区| 日韩一区二区中文字幕| 国产欧美一二三区| 亚洲线精品一区二区三区八戒| 强制捆绑调教一区二区| 国产精品一二三四五| 色综合久久综合网欧美综合网| 精品视频在线看| 久久久综合视频| 亚洲一级二级在线| 国产精品一区二区三区网站| 色综合欧美在线视频区| 精品国产免费一区二区三区香蕉| 国产精品欧美一区二区三区| 亚洲综合视频在线| 国产iv一区二区三区| 欧美日韩夫妻久久| 国产精品毛片久久久久久久| 亚洲高清免费视频| 成人美女视频在线观看18| 7777精品伊人久久久大香线蕉完整版 | 国产精品一二三| 精品视频1区2区3区| 国产精品免费看片| 另类小说欧美激情| 欧美三区在线观看| 国产精品毛片a∨一区二区三区| 日韩高清在线观看| 色欧美日韩亚洲| 欧美激情一区在线| 久久黄色级2电影| 欧美日韩一区二区三区视频| 自拍偷拍亚洲欧美日韩| 国产一区二区在线电影| 欧美丰满嫩嫩电影| 亚洲美女免费视频| 成人午夜精品在线| 久久精品这里都是精品| 老司机精品视频导航| 91精品国产综合久久福利| 一区二区三区在线影院| 99精品欧美一区二区三区综合在线| 2021久久国产精品不只是精品| 午夜成人免费视频| 欧美日韩一本到| 亚洲一区中文在线| 91免费视频观看| 亚洲四区在线观看| 99免费精品视频| 中文字幕一区二区三区色视频 | 蜜桃在线一区二区三区| 欧美日韩免费在线视频| 亚洲综合av网| 色婷婷综合久久久| 亚洲中国最大av网站| 欧美日韩精品欧美日韩精品一综合| 一区二区在线电影| 色八戒一区二区三区|