Skip to content

Commit 57e6b7a

Browse files
committed
day1_homeawork
1 parent fd7d459 commit 57e6b7a

File tree

8 files changed

+263
-0
lines changed

8 files changed

+263
-0
lines changed

group17/51075907/HomeWork/.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 exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_60"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

group17/51075907/HomeWork/.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>HomeWork</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=disabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.4
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=warning
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
11+
org.eclipse.jdt.core.compiler.source=1.3
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package day1_HomeWork;
2+
3+
4+
public class ArrayList implements List {
5+
6+
private int size = 0;
7+
8+
private Object[] elementData = new Object[100];
9+
10+
//如果数组空间超过当前大小,保证容量
11+
public void ensureCapacity( int newCapacity)
12+
{
13+
if ( newCapacity < size)
14+
return;
15+
16+
Object [] old =elementData;
17+
elementData =(Object []) new Object[newCapacity];
18+
for (int i=0; i<size(); i++ )
19+
elementData[i] =old[i];
20+
}
21+
22+
public void add(Object o){
23+
add(size(),o);
24+
return;
25+
}
26+
public void add(int index, Object o){
27+
if( elementData.length== size() )
28+
ensureCapacity ( size() *2 +1);
29+
for ( int i = size; i > index; i--)
30+
elementData[i] =elementData [i-1];
31+
elementData[index]= o;
32+
size ++;
33+
34+
}
35+
36+
public Object get(int index){
37+
if ( index<0 || index >=size())
38+
throw new ArrayIndexOutOfBoundsException();
39+
return elementData[index];
40+
}
41+
42+
public Object remove(int index){
43+
Object remove_elementData=elementData[index];
44+
for ( int i=index;i<size()-1;i++)
45+
elementData[i]= elementData[i+1];
46+
size --;
47+
return remove_elementData;
48+
}
49+
50+
public int size(){
51+
return size;
52+
}
53+
54+
public java.util.Iterator iterator(){
55+
return null;
56+
}
57+
58+
private class ArrayListIterator implements java.util.Iterator
59+
{
60+
private int current =0;
61+
62+
public boolean hasNext()
63+
{
64+
return current <size();
65+
}
66+
67+
public Object next()
68+
{
69+
if (!hasNext())
70+
throw new java.util.NoSuchElementException();
71+
return elementData[current++];
72+
}
73+
}
74+
75+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package day1_HomeWork;
2+
3+
4+
public class LinkedList implements List {
5+
6+
private Node head;
7+
8+
private int size = 0;
9+
10+
private int modCount = 0;
11+
12+
public void add(Object o){
13+
add( size(),o);
14+
return true;
15+
}
16+
public void add(int index , Object o){
17+
18+
}
19+
public Object get(int index){
20+
Node p;
21+
if ( index <0||index> size())
22+
throw new IndexOutOfBoundsException();
23+
24+
if (index < size()/2)
25+
{
26+
p=beginMarker.next;
27+
for (int i =0;i<index;i++)
28+
p=p.next;
29+
}
30+
else
31+
{
32+
p=endMarker;
33+
for (int i=size();i>index;i--)
34+
p=p.prev;
35+
}
36+
return p;
37+
}
38+
public Object remove(Node p){
39+
p.next.prev =p.prev;
40+
p.prev.next=p.next;
41+
int size;
42+
size--;
43+
int modCount;
44+
modCount++;
45+
return p.data;
46+
}
47+
48+
public int size(){
49+
return -1;
50+
}
51+
52+
public void addFirst(Node p,Object o){
53+
Node newNode= new Node (o,p.prev,p);
54+
newNode.prev.next= newNode;
55+
p.prev =newNode;
56+
size++;
57+
modCount++;
58+
}
59+
public void addLast(Object o){
60+
61+
}
62+
public Object removeFirst(int index){
63+
return remove( get(index));
64+
}
65+
public Object removeLast(){
66+
return null;
67+
}
68+
public java.util.Iterator iterator(){
69+
return new LinkedListIterator();
70+
}
71+
72+
private class LinkedListIterator implements java.util.Iterator{
73+
private Node current=beginMarker.next;
74+
private int expectedModCount=modCount;
75+
private boolean okTORemove=false;
76+
77+
public boolean haNext()
78+
{
79+
return current!= endMarker;
80+
}
81+
public Object next()
82+
{
83+
if (modCount !=expectedModCount)
84+
throw new java.util.ConcurrentModificationException();
85+
if (!=hasNext())
86+
throw new java.util.NoSuchElementException();
87+
88+
89+
}
90+
}
91+
92+
93+
private static class Node{
94+
public Node(Object o, Node p, Node n)
95+
{
96+
data =o; next=n; prev=p;
97+
}
98+
public Object data;
99+
public Node next;
100+
public Node prev;
101+
102+
}
103+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package day1_HomeWork;
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 day1_HomeWork;
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package day1_HomeWork;
2+
3+
4+
public class Stack {
5+
private ArrayList elementData = new ArrayList();
6+
7+
public void push(Object o){
8+
}
9+
10+
public Object pop(){
11+
return null;
12+
}
13+
14+
public Object peek(){
15+
return null;
16+
}
17+
public boolean isEmpty(){
18+
return false;
19+
}
20+
public int size(){
21+
return -1;
22+
}
23+
}

0 commit comments

Comments
 (0)