From dd964fcc02c934c7e0a7935badf1c811b6e42272 Mon Sep 17 00:00:00 2001
From: "wangxg922@chinaunincom.cn" <996108220@qq.com>
Date: Sun, 26 Feb 2017 11:19:53 +0800
Subject: [PATCH] =?UTF-8?q?Signed-off-by:=20996108220@qq.com=EF=BC=8C11?=
=?UTF-8?q?=E7=BB=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group11/996108220/.classpath | 6 +
group11/996108220/.gitignore | 1 +
group11/996108220/.project | 17 ++
.../src/com/coding/basic/ArrayList.java | 124 ++++++++++++
.../src/com/coding/basic/BinaryTree.java | 129 +++++++++++++
.../src/com/coding/basic/Iterator.java | 7 +
.../src/com/coding/basic/LinkedList.java | 176 ++++++++++++++++++
.../996108220/src/com/coding/basic/List.java | 9 +
.../996108220/src/com/coding/basic/Queue.java | 20 ++
.../996108220/src/com/coding/basic/Stack.java | 24 +++
10 files changed, 513 insertions(+)
create mode 100644 group11/996108220/.classpath
create mode 100644 group11/996108220/.gitignore
create mode 100644 group11/996108220/.project
create mode 100644 group11/996108220/src/com/coding/basic/ArrayList.java
create mode 100644 group11/996108220/src/com/coding/basic/BinaryTree.java
create mode 100644 group11/996108220/src/com/coding/basic/Iterator.java
create mode 100644 group11/996108220/src/com/coding/basic/LinkedList.java
create mode 100644 group11/996108220/src/com/coding/basic/List.java
create mode 100644 group11/996108220/src/com/coding/basic/Queue.java
create mode 100644 group11/996108220/src/com/coding/basic/Stack.java
diff --git a/group11/996108220/.classpath b/group11/996108220/.classpath
new file mode 100644
index 0000000000..d171cd4c12
--- /dev/null
+++ b/group11/996108220/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group11/996108220/.gitignore b/group11/996108220/.gitignore
new file mode 100644
index 0000000000..5e56e040ec
--- /dev/null
+++ b/group11/996108220/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/group11/996108220/.project b/group11/996108220/.project
new file mode 100644
index 0000000000..fe4e769dd4
--- /dev/null
+++ b/group11/996108220/.project
@@ -0,0 +1,17 @@
+
+
+ 996108220Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group11/996108220/src/com/coding/basic/ArrayList.java b/group11/996108220/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..6fe727645b
--- /dev/null
+++ b/group11/996108220/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,124 @@
+package com.coding.basic;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+ private Object[] elementData = new Object[100];
+ /**
+ * 在队尾添加元素
+ */
+ public void add(Object o){
+ if(size+1>elementData.length)this.grow(elementData);
+ else elementData[size++]=o;
+ }
+ /**
+ * 在index处添加元素,index+1到size-1元素向后移动
+ */
+ public void add(int index, Object o){
+ if(index<0||index>size){
+ System.out.println("数组越界"+index);
+ return;
+ }
+ if(size+1>elementData.length)this.grow(elementData);
+ else {
+ for(int i=size;i>=index+1;)
+ {
+ elementData[i]=elementData[--i];
+ }
+ size++;
+ elementData[index]=o;
+ }
+
+ }
+ /**
+ * 获得index处的元素elementData[index]
+ */
+ public Object get(int index){
+ //TODO越界抛出异常
+ if(index<0||index>size){
+ System.out.println("数组越界"+index);
+ return null;
+ }
+ else{
+ return elementData[index];
+ }
+ }
+ /**
+ * 移除index处的元素,将index+1到size-1的元素向前移动
+ */
+ public Object remove(int index){
+ //TODO越界抛出异常
+ if(index<0||index>=size){
+ System.out.println("数组越界"+index);
+ return null;
+ }
+ else{
+ Object value=elementData[index];
+ for(int i=index;i= size)
+ System.out.println("超过size");;
+ Object[] elementData = ArrayList.this.elementData;
+ if (i >= elementData.length)
+ System.out.println("超过length");
+ cursor = i + 1;
+ return elementData[i];
+ }
+
+ }
+ public void grow(Object[] elementData2){
+ int[] elementData=new int[elementData2.length+elementData2.length/2];
+ System.arraycopy(elementData2,0,elementData,0,elementData2.length);
+ }
+ /**
+ * 测试方法
+ * @param args
+ */
+ public static void main(String args[]){
+ ArrayList list=new ArrayList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+ list.add(6);
+ //list.add(2,0);
+ //list.remove(list.size-1);
+ System.out.println(list.size());
+ Iterator itr=list.iterator();
+ while (itr.hasNext()) {
+ System.out.println(itr.next());
+
+ }
+ }
+
+}
+
diff --git a/group11/996108220/src/com/coding/basic/BinaryTree.java b/group11/996108220/src/com/coding/basic/BinaryTree.java
new file mode 100644
index 0000000000..1b6d95b6d1
--- /dev/null
+++ b/group11/996108220/src/com/coding/basic/BinaryTree.java
@@ -0,0 +1,129 @@
+package com.coding.basic;
+
+import com.sun.corba.se.impl.orbutil.graph.Node;
+
+public class BinaryTree {
+
+ private BinaryTreeNode root=null;
+ private int size=0;
+ /**
+ * 插入节点,保持二叉树的性质
+ * @param o
+ */
+ public void insert(T o){
+ if (size==0) {
+ root=new BinaryTreeNode(o);
+ }
+ else{
+ insert(o,root);
+ }
+ size++;
+ }
+
+ private void insert(T o, BinaryTreeNode> ptr) {
+ if ((ptr.right==null&&(ptr.data.compareTo(o)<=0))){
+ ptr.right=new BinaryTreeNode(o);
+ }
+ else if (ptr.left==null&&(ptr.data.compareTo(o)>0)) {
+ ptr.left=new BinaryTreeNode(o);
+
+ }
+ else if (ptr.left!=null&&(ptr.data.compareTo(o)>0)) {
+ insert(o, ptr.left);
+ }
+ else {
+ insert(o, ptr.right);
+ }
+ }
+ private static class BinaryTreeNode {
+ private T data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+ private BinaryTreeNode(T o) {
+ this.data=o;
+ this.left=null;
+ this.right=null;
+ }
+ private BinaryTreeNode() {
+
+ }
+ }
+ /**
+ * 前序遍历
+ */
+ public void preOrder(BinaryTreeNode Node)
+ {
+ if (Node != null)
+ {
+ System.out.print(Node.data + " ");
+ preOrder(Node.left);
+ preOrder(Node.right);
+ }
+ }
+
+ /**
+ * 中序遍历
+ */
+ public void midOrder(BinaryTreeNode Node)
+ {
+ if (Node != null)
+ {
+ midOrder(Node.left);
+ System.out.print(Node.data + " ");
+ midOrder(Node.right);
+ }
+ }
+
+ /**
+ * 后序遍历
+ */
+ public void posOrder(BinaryTreeNode Node)
+ {
+ if (Node != null)
+ {
+ posOrder(Node.left);
+ posOrder(Node.right);
+ System.out.print(Node.data + " ");
+ }
+ }
+ /**
+ * @param key查找元素
+ * @param node
+ * @return 返回date的node引用
+ */
+ public BinaryTreeNode searchNode(T key,BinaryTreeNode node) {
+ if (node!=null) {
+ if (node.data.compareTo(key)==0) {
+ return node;
+ }
+ else if (node.data.compareTo(key)>0) {
+ return searchNode(key,node.left);
+ }
+ else {
+ return searchNode(key,node.right);
+ }
+ }
+ else{
+ return null;
+ }
+ }
+
+ public static void main(String[] args) {
+ BinaryTree tree=new BinaryTree();
+ tree.insert(5);
+ tree.insert(3);
+ tree.insert(1);
+ tree.insert(6);
+ tree.insert(5);
+ tree.insert(2);
+ tree.preOrder(tree.root);
+ System.out.println();
+ tree.posOrder(tree.root);
+ System.out.println();
+ tree.midOrder(tree.root);
+ System.out.println(tree.searchNode(1, tree.root).data);
+
+
+ }
+
+}
diff --git a/group11/996108220/src/com/coding/basic/Iterator.java b/group11/996108220/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..dbe8b9afb2
--- /dev/null
+++ b/group11/996108220/src/com/coding/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group11/996108220/src/com/coding/basic/LinkedList.java b/group11/996108220/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..be0b354bc2
--- /dev/null
+++ b/group11/996108220/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,176 @@
+package com.coding.basic;
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size=0;
+/**
+ * 增加节点
+ */
+ public void add(Object o){
+ if(size==0){
+ head=new Node();
+ head.data=o;
+ head.next=null;
+ size++;
+ }
+ else{
+ addLast(o);
+ }
+
+ }
+/**
+ * 在index(0~size)处添加元素
+ */
+ public void add(int index , Object o){
+
+ if(index<0||index>size){
+ System.out.println("index超出范围"+index);
+ return;
+ }
+ if(index==0)addFirst( o);
+ else if(index==size)addLast(o);
+ else{
+ Node ptr=head;
+ for(int i=1;i=size)return null;
+ else{
+ Node ptr=head;
+ for(int i=0;i=size)return null;
+ else if(index==0)return removeFirst();
+ else if(index==size-1)return removeLast();
+ else{
+ Node ptr=head;
+ for(int i=1;i