Skip to content

Commit 88144c6

Browse files
committed
data structure
1 parent ab88916 commit 88144c6

File tree

10 files changed

+290
-0
lines changed

10 files changed

+290
-0
lines changed

group10/364298692/cs/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

group10/364298692/cs/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>cs</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.coding.basic;
2+
3+
import java.util.Arrays;
4+
5+
public class ArrayList implements List{
6+
7+
private int size = 0;
8+
9+
private Object[] elementData;
10+
11+
public ArrayList(int initialCapacity){
12+
elementData = new Object[initialCapacity];
13+
}
14+
15+
public ArrayList(){
16+
elementData = new Object[10];
17+
}
18+
19+
public void ensureCapacity(int minCapacity){
20+
int oldCapacity = elementData.length;
21+
if(minCapacity > oldCapacity){
22+
Object[] oldData = elementData;
23+
int newCapacity = (oldCapacity * 3) / 2 + 1;
24+
if(minCapacity > newCapacity){
25+
newCapacity = minCapacity;
26+
}
27+
elementData = Arrays.copyOf(elementData, newCapacity);
28+
}
29+
}
30+
31+
public void add(Object o){
32+
ensureCapacity(size + 1);
33+
elementData[size] = o;
34+
size++;
35+
}
36+
public void add(int index, Object o){
37+
ensureCapacity(size + 1);
38+
for(int i = size-1; i >= index; i--){
39+
elementData[i+1] = elementData[i];
40+
}
41+
elementData[index] = o;
42+
size++;
43+
}
44+
45+
public Object get(int index){
46+
if(index > size-1){
47+
return null;
48+
}else{
49+
return elementData[index];
50+
}
51+
}
52+
53+
public Object remove(int index){
54+
if(index > size-1){
55+
return null;
56+
}else{
57+
Object obj = elementData[index];
58+
for(int i=index; i<size-1; i++){
59+
elementData[index] = elementData[index+1];
60+
}
61+
size--;
62+
return obj;
63+
}
64+
}
65+
66+
public int size(){
67+
return size;
68+
}
69+
70+
public Iterator iterator(){
71+
72+
return null;
73+
}
74+
75+
}
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
7+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.coding.basic;
2+
3+
public class LinkedList implements List {
4+
5+
private Node head;
6+
7+
private int size;
8+
9+
public void add(Object o){
10+
addLast(o);
11+
}
12+
13+
public void add(int index , Object o){
14+
Node node = head;
15+
for(int i = 0; i < index; i++){
16+
node = node.next;
17+
}
18+
Node newNode = new Node();
19+
newNode.data = o;
20+
newNode.next = node.next;
21+
node.next = newNode;
22+
size++;
23+
}
24+
public Object get(int index){
25+
if(index > size-1){
26+
return null;
27+
}else{
28+
Node node = head;
29+
for(int i = 0; i < index; i++){
30+
node = node.next;
31+
}
32+
return node.data;
33+
}
34+
}
35+
public Object remove(int index){
36+
if(index > size-1){
37+
return null;
38+
}else if(index == 0){
39+
Object obj = head.data;
40+
head = head.next;
41+
size--;
42+
return obj;
43+
}else{
44+
Node node = head;
45+
//获得被删掉节点的前一个节点
46+
for(int i = 0; i < index-1; i++){
47+
node = node.next;
48+
}
49+
Object obj = node.next.data;
50+
node.next = node.next.next;
51+
size--;
52+
return obj;
53+
}
54+
}
55+
56+
public int size(){
57+
return size;
58+
}
59+
60+
public void addFirst(Object o){
61+
Node newHead = new Node();
62+
newHead.data = o;
63+
newHead.next = head;
64+
head = newHead;
65+
size++;
66+
}
67+
public void addLast(Object o){
68+
Node node = head;
69+
while(node.next != null){
70+
node = node.next;
71+
}
72+
Node newNode = new Node();
73+
newNode.data = o;
74+
node.next = newNode;
75+
size++;
76+
}
77+
public Object removeFirst(){
78+
return remove(0);
79+
}
80+
public Object removeLast(){
81+
return remove(size);
82+
}
83+
public Iterator iterator(){
84+
return null;
85+
}
86+
87+
88+
private static class Node{
89+
Object data;
90+
Node next;
91+
}
92+
}
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)