Skip to content

Commit 954c777

Browse files
committed
重新提交
1 parent 9780877 commit 954c777

File tree

8 files changed

+236
-0
lines changed

8 files changed

+236
-0
lines changed

group20/452472201/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.coding.basic;
2+
3+
public class ArrayList implements List {
4+
5+
private int size=0;
6+
7+
private Object[] elementData =new Object[10];
8+
9+
10+
//数组扩容
11+
private void ensureCapacityInternal(){
12+
if(size==elementData.length){
13+
Object[] newArray = new Object[size*2];
14+
System.arraycopy(elementData, 0, newArray, 0, elementData.length);
15+
elementData=newArray;
16+
}
17+
}
18+
19+
public void add(Object o){
20+
ensureCapacityInternal();
21+
elementData[size]=o;
22+
size++;
23+
}
24+
25+
public void add(int index, Object o){
26+
ensureCapacityInternal();
27+
if(index<0){
28+
try {
29+
throw new Exception();
30+
} catch (Exception e) {
31+
e.printStackTrace();
32+
}
33+
}
34+
35+
System.arraycopy(elementData, index, elementData, index+1,size-index );
36+
elementData[index]=o;
37+
size++;
38+
}
39+
40+
public Object get(int index){
41+
if(index<0||index>=size){
42+
try {
43+
throw new Exception();
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
47+
}
48+
return elementData[index];
49+
}
50+
51+
public Object remove(int index){
52+
if(index>=size){
53+
try {
54+
throw new Exception();
55+
} catch (Exception e) {
56+
e.printStackTrace();
57+
}
58+
}else{
59+
60+
int numMoved=size-index-1;
61+
if(numMoved>0){
62+
System.arraycopy(elementData, index+1, elementData, index, numMoved);
63+
}
64+
65+
elementData[size--] = null;
66+
}
67+
return index;
68+
69+
}
70+
71+
72+
public int size(){
73+
return size;
74+
}
75+
76+
77+
private class Iter implements Iterator {
78+
//计数器
79+
private int coursor=-1;
80+
//判断是否存在下一个
81+
public boolean hasNext(){
82+
return coursor+1<size;
83+
}
84+
//获取下一个
85+
public String next(){
86+
coursor++;
87+
return (String) elementData[coursor];
88+
}
89+
}
90+
public Iterator iterator(){
91+
92+
return new Iter();
93+
94+
}
95+
}
96+
97+
98+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTreeNode {
4+
5+
private Object data;
6+
private BinaryTreeNode left;
7+
private BinaryTreeNode right;
8+
9+
public Object getData() {
10+
return data;
11+
}
12+
public void setData(Object data) {
13+
this.data = data;
14+
}
15+
public BinaryTreeNode getLeft() {
16+
return left;
17+
}
18+
public void setLeft(BinaryTreeNode left) {
19+
this.left = left;
20+
}
21+
public BinaryTreeNode getRight() {
22+
return right;
23+
}
24+
public void setRight(BinaryTreeNode right) {
25+
this.right = right;
26+
}
27+
28+
public BinaryTreeNode insert(Object o){
29+
return null;
30+
}
31+
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
7+
}
8+
9+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.coding.basic;
2+
3+
public class LinkedList implements List {
4+
5+
private Node head;
6+
7+
public void add(Object o){
8+
9+
}
10+
public void add(int index , Object o){
11+
12+
}
13+
public Object get(int index){
14+
return null;
15+
}
16+
public Object remove(int index){
17+
return null;
18+
}
19+
20+
public int size(){
21+
return -1;
22+
}
23+
24+
public void addFirst(Object o){
25+
26+
}
27+
public void addLast(Object o){
28+
29+
}
30+
public Object removeFirst(){
31+
return null;
32+
}
33+
public Object removeLast(){
34+
return null;
35+
}
36+
public Iterator iterator(){
37+
return null;
38+
}
39+
40+
41+
private static class Node{
42+
Object data;
43+
Node next;
44+
45+
}
46+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coding.basic;
2+
3+
public interface List {
4+
public void add(Object o);
5+
public void add(int index, Object o);
6+
public Object get(int index);
7+
public Object remove(int index);
8+
public int size();
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.coding.basic;
2+
3+
public class Queue {
4+
5+
public void enQueue(Object o){
6+
}
7+
8+
public Object deQueue(){
9+
return null;
10+
}
11+
12+
public boolean isEmpty(){
13+
return false;
14+
}
15+
16+
public int size(){
17+
return -1;
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.coding.basic;
2+
3+
public class Stack {
4+
private ArrayList elementData = new ArrayList();
5+
6+
public void push(Object o){
7+
}
8+
9+
public Object pop(){
10+
return null;
11+
}
12+
13+
public Object peek(){
14+
return null;
15+
}
16+
public boolean isEmpty(){
17+
return false;
18+
}
19+
public int size(){
20+
return -1;
21+
}
22+
}

0 commit comments

Comments
 (0)