Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangshaojie committed Feb 26, 2017
2 parents 51b90df + 2277d06 commit f8f3656
Show file tree
Hide file tree
Showing 215 changed files with 11,743 additions and 6 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@
*.war
*.ear

*.iml
*.idea


# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

#ide config
.metadata
.recommenders
<<<<<<< HEAD
<<<<<<< HEAD
.idea
=======
=======


#macOS
.DS_Store

>>>>>>> refs/remotes/onlyliuxin/master
.idea/
*.iml
rebel.*
.rebel.*

target
<<<<<<< HEAD
>>>>>>> refs/remotes/onlyliuxin/master
=======

>>>>>>> refs/remotes/onlyliuxin/master
1 change: 1 addition & 0 deletions group12/2258659044/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is my projectWorkcpace!
94 changes: 94 additions & 0 deletions group12/2258659044/zj-2017/src/com/coding/basic/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.coding.basic;

import java.util.NoSuchElementException;

public class ArrayList implements List {

private int size = 0;
/*扩容因子*/
private static final int GENE = 10;

private Object[] elementData = new Object[10];
/*扩容引用*/
private Object[] newElementData;

public void add(Object o){
grow();
elementData[size] = o;
size ++;
}
public void add(int index, Object o){

if(index>size){
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size);
}
grow();
if(index<size){//长度足够需要移动
newElementData = new Object[elementData.length];
System.arraycopy(elementData, 0, newElementData, 0, index);
System.arraycopy(elementData, index, newElementData, index+1, size-index);
elementData = newElementData;
}
elementData[index] = o;
size ++;
}

public Object get(int index){

if(index>size){
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size);
}
return elementData[index];
}

public Object remove(int index){

Object o = elementData[index];
System.arraycopy(elementData, index+1, elementData, index, size-(index+1));
size --;
return o;
}

public int size(){
return size;
}

/**
* 扩容,扩容因子为10
*/
private void grow(){

if(size>=elementData.length){//长度不够需要扩容
newElementData = new Object[size+GENE];
System.arraycopy(elementData, 0, newElementData, 0, elementData.length);
elementData = newElementData;
}
}


public Iterator iterator(){

return new Itr();
}

private class Itr implements Iterator{

int cursor;
@Override
public boolean hasNext() {
return cursor != ArrayList.this.size;
}

@Override
public Object next() {

int i = this.cursor;
if (i >= ArrayList.this.size){
throw new NoSuchElementException();
}
this.cursor = (i + 1);
return ArrayList.this.elementData[i];
}

}
}
64 changes: 64 additions & 0 deletions group12/2258659044/zj-2017/src/com/coding/basic/BinaryTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.coding.basic;

public class BinaryTree {

//根节点
private BinaryTreeNode root;

@SuppressWarnings({ "rawtypes", "unchecked" })
public <T extends Comparable<? super T>> BinaryTreeNode insert(T o){

BinaryTreeNode treeNode = new BinaryTreeNode();
treeNode.setData(o);
if(root == null){
root = treeNode;
}else{
BinaryTreeNode currentNode = root;
BinaryTreeNode parent;
while(true){
parent = currentNode;
if(((Comparable)currentNode.getData()).compareTo(o)>0){//向左放
currentNode = currentNode.getLeft();
if(currentNode == null){
parent.setLeft(treeNode);
treeNode.setParent(parent);
break;
}
}else{//向右放
currentNode = currentNode.getRight();
if(currentNode == null){
parent.setRight(treeNode);
treeNode.setParent(parent);
break;
}
}
}
}
return treeNode;
}

/**
* 先序遍历
* @param node
* @return
*/
public List traversalBefore(BinaryTreeNode node){
//所有数据集合
List datas = new ArrayList();
return traversal(node,datas);
}
private List traversal(BinaryTreeNode node,List datas){

if(node !=null){
datas.add(node.getData());
traversal(node.getLeft(),datas);
traversal(node.getRight(),datas);
}
return datas;
}

public BinaryTreeNode getRoot() {
return root;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.coding.basic;
public class BinaryTreeNode {

private Object data;
//父节点
private BinaryTreeNode parent;
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 getParent() {
return parent;
}
public void setParent(BinaryTreeNode parent) {
this.parent = parent;
}
}
8 changes: 8 additions & 0 deletions group12/2258659044/zj-2017/src/com/coding/basic/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.coding.basic;

public interface Iterator {

public boolean hasNext();
public Object next();

}
137 changes: 137 additions & 0 deletions group12/2258659044/zj-2017/src/com/coding/basic/LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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){

Node addNode = new Node();
addNode.data = o;
if(size==0){
head = addNode;
}else{
//获取最后一个节点
Node lastNode = getPointNode(size-1);
lastNode.next = addNode;
}
size++;
}
public void add(int index , Object o){

Node addNode = new Node();
addNode.data = o;
if(index == 0){
addFirst(o);
return;
}
if(index == size){
Node lastNode = getPointNode(size-1);
lastNode.next = addNode;
}else{
Node pointNode = getPointNode(index);
Node prePointNode = getPointNode(index-1);
prePointNode.next = addNode;
addNode.next = pointNode;
}
size ++;
}
public Object get(int index){

Node node = getPointNode(index);
return node.data;
}

public Object remove(int index){

Node pointNode = getPointNode(index);
Node nextPointNode = getPointNode(index+1);
if(index ==0){
head = nextPointNode;
}else{
Node prePointNode = getPointNode(index-1);
prePointNode.next = nextPointNode;
}
size --;
return pointNode.data;
}

public int size(){
return size;
}

public void addFirst(Object o){

Node secondNode = head;
head = new Node();
head.data = o;
if(size>0){
head.next = secondNode;
}
size ++;
}

public void addLast(Object o){
add(o);
}

public Object removeFirst(){

return remove(0);
}

public Object removeLast(){

return remove(size-1);
}
public Iterator iterator(){
return new Itr();
}

private class Itr implements Iterator{

int cursor;
@Override
public boolean hasNext() {
return cursor != LinkedList.this.size;
}

@Override
public Object next() {

int i = this.cursor;
if (i >= LinkedList.this.size){
throw new NoSuchElementException();
}
this.cursor = (i + 1);
return LinkedList.this.get(i);
}

}

/**
* 获取指定的节点
* @return
*/
private Node getPointNode(int index){

if(index>size){
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size+"");
}
Node node = head;
for (int i = 0; i < index; i++) {
node = node.next;
}
return node;
}

private static class Node{
Object data;
Node next;

}
}
10 changes: 10 additions & 0 deletions group12/2258659044/zj-2017/src/com/coding/basic/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.coding.basic;

public interface List {

public void add(Object o);
public void add(int index, Object o);
public Object get(int index);
public Object remove(int index);
public int size();
}
Loading

0 comments on commit f8f3656

Please sign in to comment.