Skip to content

Commit b8ac309

Browse files
authored
Merge pull request onlyliuxin#8 from lihhj/master
20170226-176653813
2 parents 9191dae + 893df80 commit b8ac309

File tree

11 files changed

+345
-0
lines changed

11 files changed

+345
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
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>1766538130226Lesson</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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.coding.basic;
2+
3+
public class ArrayList implements List {
4+
5+
private int size = 0;
6+
private Object[] obj = new Object[5];
7+
8+
@Override
9+
public void add(Object o) {
10+
if(this.size < 0 )
11+
System.out.print("Error");
12+
this.extend(100);
13+
obj[this.size] = o;
14+
this.size ++;
15+
}
16+
17+
@Override
18+
public void add(int index, Object o) {
19+
20+
if(index < 0)
21+
System.out.println("Error");
22+
if(index < this.size){
23+
extend(100);
24+
for(int i = this.size;i < index; i--){
25+
obj[i+1] = obj[i];
26+
}
27+
obj[index] = o;
28+
}else if(index >= size){
29+
extend(100);
30+
obj[size] = o;
31+
}
32+
this.size++;
33+
}
34+
35+
@Override
36+
public Object get(int index) {
37+
if(index < 0 || index > size){
38+
System.out.println("Error");
39+
return null;
40+
}
41+
return obj[index];
42+
}
43+
44+
@Override
45+
public Object remove(int index) {
46+
if(index < 0 || index > size){
47+
System.out.println("Error");
48+
return null;
49+
}
50+
for(int i = index;i <= size;i++){
51+
obj[i] = obj[i+1];
52+
}
53+
size--;
54+
return obj[index];
55+
}
56+
57+
@Override
58+
public int size() {
59+
return size;
60+
}
61+
public int length(){
62+
return obj.length;
63+
}
64+
public void extend(int newLength){
65+
if (this.size >= obj.length){
66+
//À©Õ¹Êý×é
67+
Object[] old = obj;
68+
obj = new Object[size+newLength];
69+
for(int i = 0;i < size; i++){
70+
obj[i] = old[i];
71+
}
72+
}
73+
return;
74+
}
75+
public void Iteror(){
76+
for(int i = 0 ;i < size ; i++){
77+
System.out.println(obj[i]);
78+
}
79+
}
80+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.coding.basic;
2+
3+
public class LinkList implements List{
4+
5+
private Node head; //头结点不计算个数
6+
private static class Node{
7+
Object data;
8+
Node next;
9+
}
10+
11+
@Override
12+
public void add(Object o) {
13+
//第一步没有想到
14+
if(null == head){
15+
head = new Node();
16+
head.next = null;
17+
head.data = o;
18+
}else{
19+
//尾插入法
20+
//Node t = new Node();
21+
Node t;
22+
Node ins = new Node();
23+
t = head;
24+
while(t.next != null){
25+
t = t.next;
26+
}
27+
t.next = ins;
28+
ins.next = null;
29+
ins.data = o;
30+
}
31+
}
32+
33+
@Override
34+
public void add(int index, Object o) {
35+
if(index < 0 ){
36+
System.out.println("Error");
37+
}else if(index == 0 || index == 1){
38+
Node t = new Node();
39+
t.next = head.next;
40+
head.next = t;
41+
t.data = o;
42+
}else{
43+
Node t = new Node();//当前节点
44+
Node p = new Node();//前一个节点
45+
t = head.next;
46+
for(int i = 1;i < index;i++){
47+
p = t;
48+
t = t.next;
49+
}
50+
Node ins = new Node();
51+
p.next = ins;
52+
ins.next = t;
53+
ins.data = o;
54+
}
55+
56+
}
57+
58+
@Override
59+
public Object get(int index) {
60+
if(index < 0 || head == null){
61+
System.out.println("Error");
62+
return null;
63+
}else{
64+
Node t ;
65+
t = head;
66+
for(int i = 1;i < index;i++){
67+
t = t.next;
68+
}
69+
return t.data;
70+
}
71+
}
72+
73+
@Override
74+
public Object remove(int index) {
75+
76+
return null;
77+
}
78+
79+
public void display(){
80+
if(head == null){
81+
System.out.println("No Data");
82+
}else{
83+
Node t ;
84+
t = head;
85+
while(t != null){
86+
System.out.println("******"+t.data);
87+
t = t.next;
88+
}
89+
}
90+
91+
}
92+
@Override
93+
public int size() {
94+
return 0;
95+
}
96+
}
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.coding.basic;
2+
3+
public class Queue {
4+
5+
private LinkList elementData = new LinkList();
6+
private int front = 0;
7+
private int rear = 0;
8+
9+
10+
public void enQueue(Object o){
11+
elementData.add(o);
12+
rear++;
13+
}
14+
public Object deQueue(){
15+
if(!isEmpty()){
16+
Object obj = elementData.remove(front);
17+
front++;
18+
return obj;
19+
}else{
20+
System.out.println("Queue is empty");
21+
return null;
22+
}
23+
}
24+
public boolean isEmpty(){
25+
if(front > rear){
26+
return true;
27+
}
28+
return false;
29+
}
30+
31+
public int size(){
32+
return rear-front+1;
33+
}
34+
}
35+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.coding.basic;
2+
3+
public class Stack {
4+
5+
//
6+
private ArrayList elementData = new ArrayList();
7+
private int top = 0;
8+
9+
public void push(Object o){
10+
elementData.add(o);
11+
top++;
12+
}
13+
14+
public Object pop(){
15+
if(!isEmpty()){
16+
System.out.println("stack is empoty");
17+
return null;
18+
}
19+
Object obj = elementData.remove(top);
20+
top--;
21+
return obj;
22+
}
23+
24+
public Object peek(){
25+
return elementData.get(top);
26+
}
27+
28+
public boolean isEmpty(){
29+
if(top != 0){
30+
return true;
31+
}
32+
return false;
33+
}
34+
35+
public int size(){
36+
return top++;
37+
}
38+
39+
40+
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.coding.basic;
2+
3+
import static org.junit.Assert.*;
4+
5+
public class Test {
6+
7+
@org.junit.Test
8+
public void test() {
9+
10+
/* ArrayList al = new ArrayList();
11+
al.add(1);
12+
al.add(2);
13+
al.add(3);
14+
al.add(4);
15+
al.add(5);
16+
al.add(200);
17+
al.add(10,100);
18+
al.Iteror();
19+
//System.out.println(al.length());
20+
//System.out.println(al.size());
21+
System.out.println("==================");
22+
al.remove(0);
23+
al.Iteror();*/
24+
25+
LinkList ls = new LinkList();
26+
ls.add(100);
27+
ls.add(300);
28+
ls.add(500);
29+
ls.add(1000);
30+
ls.add(3,2000);
31+
ls.display();
32+
System.out.println(ls.get(4));
33+
}
34+
35+
}
36+
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>

0 commit comments

Comments
 (0)