Skip to content

Commit c04c587

Browse files
committed
work1
1 parent d4a25d6 commit c04c587

File tree

12 files changed

+453
-0
lines changed

12 files changed

+453
-0
lines changed

group05/441517454/work1/.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/441517454/work1/.gitignore

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

group05/441517454/work1/.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>work1</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: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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[100];
8+
9+
public void add(Object o){
10+
11+
if(size<elementData.length)
12+
{elementData[size] = o;
13+
this.size++;}
14+
else{
15+
elementData = grow(elementData,1);
16+
elementData[size] = o;
17+
this.size++;
18+
}
19+
20+
21+
}
22+
23+
public void add(int index, Object o){
24+
if(index<(this.size)&&this.size<elementData.length)
25+
{
26+
for(int i=this.size;i>index;i--){
27+
elementData[i]=elementData[i-1];
28+
}
29+
elementData[index] = o;
30+
this.size++;
31+
}
32+
else if(index<(this.size)&&this.size==elementData.length)
33+
{
34+
elementData = grow(elementData,1);
35+
elementData[index] = o;
36+
this.size++;
37+
}
38+
else{
39+
System.out.println("index/>size¼ÓÈëʧ°Ü");
40+
41+
}
42+
43+
44+
}
45+
46+
public Object get(int index){
47+
48+
if(this.size>0&&index<(this.size))
49+
return elementData[index];
50+
else{
51+
return null;
52+
}
53+
}
54+
55+
public Object remove(int index){
56+
57+
if(this.size>0&&index<(this.size))
58+
{ Object o= elementData[index];
59+
for(int i=index;i<this.size;i++){
60+
elementData[i]=elementData[i+1];
61+
}
62+
this.size--;
63+
return o;
64+
65+
}
66+
else{
67+
return null;
68+
}
69+
}
70+
71+
public int size(){
72+
return this.size;
73+
}
74+
75+
public Iterator iterator(){
76+
return new ArrayListIterator(this);
77+
}
78+
79+
private static Object[] grow (Object[]src,int size){
80+
Object[] target = new Object[src.length+size];
81+
System.arraycopy(src, 0, target, 0, src.length);
82+
return target;
83+
}
84+
private class ArrayListIterator implements Iterator{
85+
private ArrayList arrayList;
86+
private int pos = 0;
87+
public ArrayListIterator(ArrayList arrayList) {
88+
this.arrayList =arrayList;
89+
90+
}
91+
92+
@Override
93+
public boolean hasNext() {
94+
pos++;
95+
if(pos>arrayList.size){
96+
return false;
97+
}else
98+
return true;
99+
}
100+
101+
@Override
102+
public Object next() {
103+
104+
return arrayList.get(pos-1);
105+
}}
106+
}
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: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package com.coding.basic;
2+
3+
4+
5+
public class LinkedList implements List {
6+
7+
private Node head;
8+
private Node body;
9+
//private Node body1;
10+
private int size = 0;
11+
12+
13+
public void add(Object o){
14+
if(null == head){
15+
head = new Node();
16+
head.data = o;
17+
head.next = null;
18+
size++;
19+
}
20+
// else if(head.next == null){
21+
//
22+
// head.next =new Node();
23+
// head.next.data = o;
24+
// head.next.next = null;
25+
// body=head.next;
26+
// size++;
27+
// }
28+
else {
29+
body=head;
30+
while(!(body.next ==null))
31+
{body =body.next;}
32+
body.next =new Node();
33+
body.next.data =o;
34+
body.next.next =null;
35+
size++;
36+
}
37+
38+
39+
}
40+
public void add(int index , Object o){
41+
42+
}
43+
public Object get(int index){
44+
if (index<size)
45+
{body=head;
46+
for (int i=0;i<index;i++)
47+
{
48+
body =body.next;
49+
}
50+
return body.data;
51+
}else return null;
52+
53+
}
54+
public Object remove(int index){
55+
if (index<size&&index>1)
56+
{body=head;
57+
for (int i=0;i<index-1;i++)
58+
{
59+
body =body.next;
60+
}
61+
body.next=body.next.next;
62+
size--;
63+
return body.next.data;
64+
}else return null;
65+
66+
}
67+
68+
public int size(){
69+
return this.size;
70+
}
71+
72+
public void addFirst(Object o){
73+
if(null == head){
74+
head = new Node();
75+
head.data = o;
76+
head.next = null;
77+
size++;
78+
}else {
79+
body =new Node();
80+
body.data = o;
81+
body.next = head;
82+
head=body;
83+
size++;
84+
}
85+
}
86+
public void addLast(Object o){
87+
if(!(head==null))
88+
{
89+
body=head;
90+
while(!(body.next ==null))
91+
{body =body.next;}
92+
body.next =new Node();
93+
body.next.data =o;
94+
body.next.next =body.next;
95+
size++;
96+
}else
97+
System.out.println("ÇëÏȽ¨Á¢Í·½áµã");
98+
99+
}
100+
public Object removeFirst(){
101+
if(!(head==null))
102+
{
103+
body=head;
104+
head =head.next;
105+
size--;
106+
return body.data;
107+
}else
108+
109+
return null;
110+
}
111+
public Object removeLast(){
112+
if (!(head==null))
113+
{body=head;
114+
for (int i=0;i<size-2;i++)
115+
{
116+
body =body.next;
117+
}
118+
body.next=body.next;
119+
size--;
120+
return body.next.data;
121+
}else return null;
122+
123+
}
124+
public Iterator iterator(){
125+
return new LinkedListIterator(this);
126+
}
127+
128+
129+
private static class Node{
130+
Object data;
131+
Node next;
132+
133+
}
134+
private class LinkedListIterator implements Iterator{
135+
private LinkedList linkedList;
136+
private int pos = 0;
137+
public LinkedListIterator(LinkedList linkedList) {
138+
this.linkedList =linkedList;
139+
140+
}
141+
142+
@Override
143+
public boolean hasNext() {
144+
pos++;
145+
if(pos>linkedList.size){
146+
return false;
147+
}else
148+
return true;
149+
}
150+
151+
@Override
152+
public Object next() {
153+
154+
return linkedList.get(pos-1);
155+
}}
156+
}
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.coding.basic;
2+
3+
public class Queue {
4+
private ArrayList elementData = new ArrayList();
5+
public void enQueue(Object o){
6+
elementData.add(o);
7+
}
8+
9+
public Object deQueue(){
10+
11+
if(elementData.size()>0)
12+
13+
{
14+
elementData.remove(0);
15+
return elementData.remove(0);
16+
}
17+
else return null;
18+
}
19+
20+
public boolean isEmpty(){
21+
if(elementData.size()>0)
22+
return false;
23+
else return true;
24+
25+
}
26+
27+
public int size(){
28+
return elementData.size();
29+
}
30+
}

0 commit comments

Comments
 (0)