Skip to content

Commit 4ea6342

Browse files
committed
Merge remote-tracking branch 'refs/remotes/onlyliuxin/master'
# Conflicts: # .gitignore
2 parents 089326e + d9c0269 commit 4ea6342

File tree

215 files changed

+11743
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+11743
-6
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,35 @@
77
*.war
88
*.ear
99

10+
*.iml
11+
*.idea
12+
13+
1014
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1115
hs_err_pid*
1216

1317
#ide config
1418
.metadata
1519
.recommenders
1620
<<<<<<< HEAD
21+
<<<<<<< HEAD
1722
.idea
1823
=======
24+
=======
25+
26+
27+
#macOS
28+
.DS_Store
29+
30+
>>>>>>> refs/remotes/onlyliuxin/master
1931
.idea/
2032
*.iml
2133
rebel.*
2234
.rebel.*
2335

2436
target
37+
<<<<<<< HEAD
38+
>>>>>>> refs/remotes/onlyliuxin/master
39+
=======
40+
2541
>>>>>>> refs/remotes/onlyliuxin/master

group12/2258659044/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is my projectWorkcpace!
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.coding.basic;
2+
3+
import java.util.NoSuchElementException;
4+
5+
public class ArrayList implements List {
6+
7+
private int size = 0;
8+
/*扩容因子*/
9+
private static final int GENE = 10;
10+
11+
private Object[] elementData = new Object[10];
12+
/*扩容引用*/
13+
private Object[] newElementData;
14+
15+
public void add(Object o){
16+
grow();
17+
elementData[size] = o;
18+
size ++;
19+
}
20+
public void add(int index, Object o){
21+
22+
if(index>size){
23+
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size);
24+
}
25+
grow();
26+
if(index<size){//长度足够需要移动
27+
newElementData = new Object[elementData.length];
28+
System.arraycopy(elementData, 0, newElementData, 0, index);
29+
System.arraycopy(elementData, index, newElementData, index+1, size-index);
30+
elementData = newElementData;
31+
}
32+
elementData[index] = o;
33+
size ++;
34+
}
35+
36+
public Object get(int index){
37+
38+
if(index>size){
39+
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size);
40+
}
41+
return elementData[index];
42+
}
43+
44+
public Object remove(int index){
45+
46+
Object o = elementData[index];
47+
System.arraycopy(elementData, index+1, elementData, index, size-(index+1));
48+
size --;
49+
return o;
50+
}
51+
52+
public int size(){
53+
return size;
54+
}
55+
56+
/**
57+
* 扩容,扩容因子为10
58+
*/
59+
private void grow(){
60+
61+
if(size>=elementData.length){//长度不够需要扩容
62+
newElementData = new Object[size+GENE];
63+
System.arraycopy(elementData, 0, newElementData, 0, elementData.length);
64+
elementData = newElementData;
65+
}
66+
}
67+
68+
69+
public Iterator iterator(){
70+
71+
return new Itr();
72+
}
73+
74+
private class Itr implements Iterator{
75+
76+
int cursor;
77+
@Override
78+
public boolean hasNext() {
79+
return cursor != ArrayList.this.size;
80+
}
81+
82+
@Override
83+
public Object next() {
84+
85+
int i = this.cursor;
86+
if (i >= ArrayList.this.size){
87+
throw new NoSuchElementException();
88+
}
89+
this.cursor = (i + 1);
90+
return ArrayList.this.elementData[i];
91+
}
92+
93+
}
94+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTree {
4+
5+
//根节点
6+
private BinaryTreeNode root;
7+
8+
@SuppressWarnings({ "rawtypes", "unchecked" })
9+
public <T extends Comparable<? super T>> BinaryTreeNode insert(T o){
10+
11+
BinaryTreeNode treeNode = new BinaryTreeNode();
12+
treeNode.setData(o);
13+
if(root == null){
14+
root = treeNode;
15+
}else{
16+
BinaryTreeNode currentNode = root;
17+
BinaryTreeNode parent;
18+
while(true){
19+
parent = currentNode;
20+
if(((Comparable)currentNode.getData()).compareTo(o)>0){//向左放
21+
currentNode = currentNode.getLeft();
22+
if(currentNode == null){
23+
parent.setLeft(treeNode);
24+
treeNode.setParent(parent);
25+
break;
26+
}
27+
}else{//向右放
28+
currentNode = currentNode.getRight();
29+
if(currentNode == null){
30+
parent.setRight(treeNode);
31+
treeNode.setParent(parent);
32+
break;
33+
}
34+
}
35+
}
36+
}
37+
return treeNode;
38+
}
39+
40+
/**
41+
* 先序遍历
42+
* @param node
43+
* @return
44+
*/
45+
public List traversalBefore(BinaryTreeNode node){
46+
//所有数据集合
47+
List datas = new ArrayList();
48+
return traversal(node,datas);
49+
}
50+
private List traversal(BinaryTreeNode node,List datas){
51+
52+
if(node !=null){
53+
datas.add(node.getData());
54+
traversal(node.getLeft(),datas);
55+
traversal(node.getRight(),datas);
56+
}
57+
return datas;
58+
}
59+
60+
public BinaryTreeNode getRoot() {
61+
return root;
62+
}
63+
64+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.coding.basic;
2+
public class BinaryTreeNode {
3+
4+
private Object data;
5+
//父节点
6+
private BinaryTreeNode parent;
7+
private BinaryTreeNode left;
8+
private BinaryTreeNode right;
9+
10+
public Object getData() {
11+
return data;
12+
}
13+
public void setData(Object data) {
14+
this.data = data;
15+
}
16+
17+
public BinaryTreeNode getLeft() {
18+
return left;
19+
}
20+
public void setLeft(BinaryTreeNode left) {
21+
this.left = left;
22+
}
23+
24+
public BinaryTreeNode getRight() {
25+
return right;
26+
}
27+
public void setRight(BinaryTreeNode right) {
28+
this.right = right;
29+
}
30+
31+
public BinaryTreeNode getParent() {
32+
return parent;
33+
}
34+
public void setParent(BinaryTreeNode parent) {
35+
this.parent = parent;
36+
}
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
5+
public boolean hasNext();
6+
public Object next();
7+
8+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.coding.basic;
2+
3+
import java.util.NoSuchElementException;
4+
5+
public class LinkedList implements List {
6+
7+
private Node head;
8+
9+
private int size = 0;
10+
11+
public void add(Object o){
12+
13+
Node addNode = new Node();
14+
addNode.data = o;
15+
if(size==0){
16+
head = addNode;
17+
}else{
18+
//获取最后一个节点
19+
Node lastNode = getPointNode(size-1);
20+
lastNode.next = addNode;
21+
}
22+
size++;
23+
}
24+
public void add(int index , Object o){
25+
26+
Node addNode = new Node();
27+
addNode.data = o;
28+
if(index == 0){
29+
addFirst(o);
30+
return;
31+
}
32+
if(index == size){
33+
Node lastNode = getPointNode(size-1);
34+
lastNode.next = addNode;
35+
}else{
36+
Node pointNode = getPointNode(index);
37+
Node prePointNode = getPointNode(index-1);
38+
prePointNode.next = addNode;
39+
addNode.next = pointNode;
40+
}
41+
size ++;
42+
}
43+
public Object get(int index){
44+
45+
Node node = getPointNode(index);
46+
return node.data;
47+
}
48+
49+
public Object remove(int index){
50+
51+
Node pointNode = getPointNode(index);
52+
Node nextPointNode = getPointNode(index+1);
53+
if(index ==0){
54+
head = nextPointNode;
55+
}else{
56+
Node prePointNode = getPointNode(index-1);
57+
prePointNode.next = nextPointNode;
58+
}
59+
size --;
60+
return pointNode.data;
61+
}
62+
63+
public int size(){
64+
return size;
65+
}
66+
67+
public void addFirst(Object o){
68+
69+
Node secondNode = head;
70+
head = new Node();
71+
head.data = o;
72+
if(size>0){
73+
head.next = secondNode;
74+
}
75+
size ++;
76+
}
77+
78+
public void addLast(Object o){
79+
add(o);
80+
}
81+
82+
public Object removeFirst(){
83+
84+
return remove(0);
85+
}
86+
87+
public Object removeLast(){
88+
89+
return remove(size-1);
90+
}
91+
public Iterator iterator(){
92+
return new Itr();
93+
}
94+
95+
private class Itr implements Iterator{
96+
97+
int cursor;
98+
@Override
99+
public boolean hasNext() {
100+
return cursor != LinkedList.this.size;
101+
}
102+
103+
@Override
104+
public Object next() {
105+
106+
int i = this.cursor;
107+
if (i >= LinkedList.this.size){
108+
throw new NoSuchElementException();
109+
}
110+
this.cursor = (i + 1);
111+
return LinkedList.this.get(i);
112+
}
113+
114+
}
115+
116+
/**
117+
* 获取指定的节点
118+
* @return
119+
*/
120+
private Node getPointNode(int index){
121+
122+
if(index>size){
123+
throw new IndexOutOfBoundsException("Index: "+index+",Size:"+size+"");
124+
}
125+
Node node = head;
126+
for (int i = 0; i < index; i++) {
127+
node = node.next;
128+
}
129+
return node;
130+
}
131+
132+
private static class Node{
133+
Object data;
134+
Node next;
135+
136+
}
137+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coding.basic;
2+
3+
public interface List {
4+
5+
public void add(Object o);
6+
public void add(int index, Object o);
7+
public Object get(int index);
8+
public Object remove(int index);
9+
public int size();
10+
}

0 commit comments

Comments
 (0)