Skip to content

Commit

Permalink
no test
Browse files Browse the repository at this point in the history
  • Loading branch information
laoheihei committed Mar 11, 2017
1 parent 6fc5ae0 commit 9af937c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
1 change: 1 addition & 0 deletions group22/2622819383/Task1/ArrayList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//代码参考自《数据结构与算法分析》
public class ArrayList implements List {

private int size;
Expand Down
78 changes: 51 additions & 27 deletions group22/2622819383/Task1/BinaryTreeNode.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
//代码参考自《数据结构与算法分析》
public class BinaryTreeNode {

private Object data;
private BinaryTreeNode left;
private BinaryTreeNode right;

public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public BinaryTreeNode getLeft() {
return left;
}
public void setLeft(BinaryTreeNode left) {
this.left = left;
}
public BinaryTreeNode getRight() {
return right;
}
public void setRight(BinaryTreeNode right) {
this.right = right;
}

public BinaryTreeNode insert(Object o){
return null;
}

private Object data;
private BinaryTreeNode left;
private BinaryTreeNode right;

public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public BinaryTreeNode getLeft() {
return left;
}
public void setLeft(BinaryTreeNode left) {
this.left = left;
}
public BinaryTreeNode getRight() {
return right;
}
public void setRight(BinaryTreeNode right) {
this.right = right;
}

private BinaryTreeNode parrent;
private BinaryTreeNode hot; //表示search(Object o)方法返回的命中节点的父亲

public BinaryTreeNode(Object o, BinaryTreeNode p) {
data = o;
parrent = p;
}
//在以v为根的二叉树中查找关键码o,返回命中的节点(真实存在得或者虚拟存在的)
public static BinaryTreeNode search(BinaryTreeNode v, Object o, BinaryTreeNode hot) {
int vData = (int)v.getData();
int searched = (int)o;
if (v == null || vData == searched) return v;

hot = v;
return search(searched < vData ? v.getLeft() : v.getRight(), o, hot);
}

public BinaryTreeNode insert(Object o){
BinaryTreeNode node = search(this, o, this.parrent);
if (node != null) return node;

node = new BinaryTreeNode(o, hot);
if ((int)o < (int)hot.getData()) hot.setLeft(node);
else hot.setRight(node);
return node;
}

}
6 changes: 4 additions & 2 deletions group22/2622819383/Task1/LinkedList.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//代码参考自《数据结构与算法分析》
public class LinkedList implements List {

private Node header;
Expand Down Expand Up @@ -86,6 +87,7 @@ public Object next() {
}

private static class Node {
//pred、succ代表属性;pred()、succ()代表Node节点
private Object data;
private Node pred;
private Node succ;
Expand All @@ -111,14 +113,14 @@ public Node pred() {
//插入前驱节点,返回插入的新节点
public Node insertAsPred(Object data) {
Node p = new Node(data, pred, this);
pred = pred.succ = p;
pred = pred().succ = p;
return p;
}

//插入后继节点,返回插入的新节点
public Node insertAsSucc(Object data) {
Node p = new Node(data, this, succ);
succ = succ.pred = p;
succ = succ().pred = p;
return p;
}
}
Expand Down

0 comments on commit 9af937c

Please sign in to comment.