Java第26天——问题整理

前面和后面的问题都有,解决了之后会check

22天

1.this关键字的继承方式,在我们目前Java课程里面只涉及到了继承当中的子类继承父类的成员变量就是 this.父类成员变量  。所以这里我不是太能理解他到底是怎么完成继承到上面声明的树里面的根节点的。

2.后面的入队出队问题我会画一个图来在理解一遍。树里面的知识一定要整扎实一点。

  1. 数据转换的代码很短, 但要理解还是比较花时间. 反正我写的时候比较辛苦.
  2. 用了两个队列.
  3. 实际上涵盖了广度优先 (或称层次) 遍历.
	/**
	 ********************
	 * 将树转换为数据数组,包括 char 数组和 int 数组。完整二叉树中的索引。 他的结果储存在两个成员变量当中
	 * 
	 * @see #valuesArray 这个放char
	 * @see #indicesArray 这个放int
	 * 
	 *********************
	 */
	public void toDataArrays() {
		// 初始化数组
		int tempLength = getNumNodes();

		valuesArray = new char[tempLength];
		indicesArray = new int[tempLength];
		int i = 0;

		// 同时遍历和转换数组.
		CircleObjectQueue tempQueue = new CircleObjectQueue();
		tempQueue.enqueue(this);

		CircleIntQueue tempIntQueue = new CircleIntQueue();
		tempIntQueue.enQueue(0);

		// 强制转换
		BinaryCharTree tempTree = (BinaryCharTree) tempQueue.dequeue();
		int tempIndex = tempIntQueue.deQueue();

		while (tempTree != null) {
			valuesArray[i] = tempTree.value;
			indicesArray[i] = tempIndex;
			i++;

			if (tempTree.leftChild != null) {
				tempQueue.enqueue(tempTree.leftChild);
				tempIntQueue.enQueue(tempIndex * 2 + 1);
			} // Of if

			if (tempTree.rightChild != null) {
				tempQueue.enqueue(tempTree.rightChild);
				tempIntQueue.enQueue(tempIndex * 2 + 2);
			} // Of if

			tempTree = (BinaryCharTree) tempQueue.dequeue();
			tempIndex = tempIntQueue.deQueue();
		} // Of while
	}// Of toDataArrays

23天

昨天使用的队列有两种: 存储二叉树节点的队列; 存储整数的队列. 这样的话, 难道我们要为每种类型单独写一个队列? 这样显然没有充分利用代码的复用性. 实际上, 我们只需要一个存储对象的队列就够啦!

理解不够充分的问题。

/**
	 ********************
	 * 将树转换为数据数组,包括 char 数组和 int 数组。完整二叉树中的索引。 他的结果储存在两个成员变量当中 但是是以队列的形式
	 * 
	 * @see #valuesArray 这个放char
	 * @see #indicesArray 这个放int
	 *********************
	 */
	public void toDataArraysObjectQueue() {
		// 初始化.
		int tempLength = getNumNodes();

		valuesArray = new char[tempLength];
		indicesArray = new int[tempLength];
		int i = 0;

		// 同时遍历和转换
		CircleObjectQueue tempQueue = new CircleObjectQueue();
		tempQueue.enqueue(this);

		CircleObjectQueue tempIntQueue = new CircleObjectQueue();
		Integer tempIndexInteger = new Integer(0);
		tempIntQueue.enqueue(tempIndexInteger);

		BinaryCharTree tempTree = (BinaryCharTree) tempQueue.dequeue();

		int tempIndex = ((Integer) tempIntQueue.dequeue()).intValue();
		System.out.println("tempIndex = " + tempIndex);

		while (tempTree != null) {
			valuesArray[i] = tempTree.value;
			indicesArray[i] = tempIndex;
			i++;

			if (tempTree.leftChild != null) {
				tempQueue.enqueue(tempTree.leftChild);
				tempIntQueue.enqueue(new Integer(tempIndex * 2 + 1));
			} // Of if

			if (tempTree.rightChild != null) {
				tempQueue.enqueue(tempTree.rightChild);
				tempIntQueue.enqueue(new Integer(tempIndex * 2 + 2));
			} // Of if

			tempTree = (BinaryCharTree) tempQueue.dequeue();
			if (tempTree == null) {
				break;
			} // Of if

			tempIndex = ((Integer) tempIntQueue.dequeue()).intValue();
		} // Of while
	}// Of toDataArraysObjectQueue

24天,还差一点,个人认为理解就差那么一内内。

27天,就是我自己在写24天ObjectStack的时候把depth设成了静态常量,导致了后序里面的两个Stack用的是一个东西。我感觉里面还有一些底层的东西可以整。(check)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值