Skip to content

Commit 1dbd5ae

Browse files
committed
Task01
@Leon1900
1 parent 5b8d22e commit 1dbd5ae

File tree

13 files changed

+346
-0
lines changed

13 files changed

+346
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>RemoteSystemsTempFiles</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
11+
</natures>
12+
</projectDescription>

group05/515505513/Task01/.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>

group05/515505513/Task01/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

group05/515505513/Task01/.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>Task01</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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.coding.basic;
2+
3+
import java.util.NoSuchElementException;
4+
5+
public class ArrayList implements List {
6+
7+
8+
private int size = 0;
9+
private static final int DEFAULT_SIZE = 100;
10+
private Object[] elementData = new Object[DEFAULT_SIZE];
11+
12+
//添加元素
13+
public void add(Object o){
14+
add(size(),o);
15+
}
16+
17+
18+
public void add(int index, Object o){
19+
if(elementData.length==size()){
20+
ensureCapacity(size()*2 + 1);
21+
}
22+
for (int i = size; i > index; i--)
23+
elementData[i]=elementData[i-1];
24+
elementData[index] = o;
25+
size++;
26+
}
27+
//扩容
28+
public void ensureCapacity(int newCapacity){
29+
if(newCapacity < size){
30+
return;
31+
}
32+
Object[] oldElements = elementData;
33+
elementData = new Object[newCapacity];
34+
for (int i = 0; i < size; i++) {
35+
elementData[i] = oldElements[i];
36+
}
37+
}
38+
//返回固定下标的元素
39+
public Object get(int index){
40+
if(index<0 || index >=size){
41+
throw new ArrayIndexOutOfBoundsException("指定的index超过界限");
42+
}
43+
return elementData[index];
44+
}
45+
//删除指定位置的元素
46+
public Object remove(int index){
47+
Object removeElement = elementData[index];
48+
for (int i = index; i < size; i++) {
49+
elementData[i] = elementData[i+1];
50+
}
51+
size--;
52+
return removeElement;
53+
}
54+
55+
public int size(){
56+
return size;
57+
}
58+
59+
public Iterator iterator(){
60+
return new ArrayListIterator();
61+
}
62+
63+
private class ArrayListIterator implements Iterator{
64+
private int current = 0;
65+
@Override
66+
public boolean hasNext() {
67+
return current < size;
68+
}
69+
@Override
70+
public Object next() {
71+
if(!hasNext()){
72+
throw new NoSuchElementException();
73+
}
74+
return elementData[current+1];
75+
}
76+
}
77+
78+
}
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.coding.basic;
2+
3+
public class LinkedList implements List {
4+
5+
private Node head;//指针
6+
private Object element;//元素
7+
//添加一个元素
8+
public void add(Object o){
9+
10+
}
11+
//在index处添加一个元素
12+
public void add(int index , Object o){
13+
14+
}
15+
16+
public Object get(int index){
17+
return null;
18+
}
19+
//清除一个元素
20+
public Object remove(int index){
21+
return null;
22+
}
23+
24+
public int size(){
25+
return -1;
26+
}
27+
28+
public void addFirst(Object o){
29+
30+
}
31+
public void addLast(Object o){
32+
33+
}
34+
public Object removeFirst(){
35+
return null;
36+
}
37+
public Object removeLast(){
38+
return null;
39+
}
40+
public Iterator iterator(){
41+
return null;
42+
}
43+
44+
private static class Node{
45+
Object data;//元素
46+
Node next;//指针
47+
}
48+
}
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.coding.basic;
2+
3+
public class Queue {
4+
private int maxSize;//队列容量
5+
private Object[] queue;//队列
6+
private int head;//队列头,可以删除
7+
private int tail;//队列尾,可以插入
8+
9+
10+
public Queue() {
11+
this(10);
12+
}
13+
14+
public Queue(int maxSize) {
15+
if(maxSize >=0){
16+
this.maxSize = maxSize;
17+
this.queue = new Object[maxSize];
18+
head = tail = 0;
19+
}else {
20+
throw new RuntimeException("初始化大小不能小于0");
21+
}
22+
}
23+
24+
public void enQueue(Object o){
25+
if(tail == maxSize){
26+
throw new RuntimeException("队列已满,无法插入新的元素!");
27+
}else {
28+
queue[tail++] = o;
29+
}
30+
}
31+
32+
public Object deQueue(){
33+
if(isEmpty()){
34+
throw new RuntimeException("空队列异常!");
35+
}else {
36+
Object value = queue[head];
37+
queue[head++] = null;
38+
return value;
39+
}
40+
}
41+
//队列是否为空
42+
public boolean isEmpty(){
43+
return head==tail?true:false;
44+
}
45+
46+
public int size(){
47+
return tail-head;
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.coding.basic;
2+
3+
public class Stack {
4+
private Object[] data;
5+
private int capacity;
6+
private int size;
7+
public Stack(){
8+
capacity = 16;
9+
size = 0;
10+
data = new Object[capacity];
11+
}
12+
public void push(Object o){
13+
if(size < capacity){
14+
data[size++] = o;
15+
}else {
16+
ensureCapacity();
17+
data[size++] = o;
18+
}
19+
}
20+
21+
private void ensureCapacity() {
22+
capacity = capacity*2;
23+
}
24+
public Object pop(){
25+
if(size > 0){
26+
System.out.println(data[size-1]);
27+
//data[size--] = null;
28+
}else {
29+
System.out.println("Empty stack");
30+
}
31+
size--;
32+
return data[size];
33+
}
34+
35+
public Object peek(){
36+
if(size>0){
37+
return data[size-1];
38+
}else {
39+
return null;
40+
}
41+
}
42+
public boolean isEmpty(){
43+
44+
return size==0;
45+
}
46+
public int size(){
47+
return size;
48+
}
49+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.coding.basic;
2+
3+
public class TestExample {
4+
5+
public static void main(String[] args) {
6+
/*Stack mystack = new Stack();
7+
for (int i = 0; i < 10; i++) {
8+
mystack.push(i);
9+
}
10+
for (int i = 0; i < 10; i++) {
11+
mystack.pop();
12+
System.out.println("==="+mystack.peek());
13+
}*/
14+
15+
/*Test Queue
16+
Queue myQqueue = new Queue(10);
17+
for (int i = 0; i < 10; i++) {
18+
myQqueue.enQueue(i);
19+
}
20+
for (int i = 0; i < 10; i++) {
21+
System.out.println(myQqueue.deQueue());
22+
}*/
23+
24+
25+
}
26+
27+
}

0 commit comments

Comments
 (0)