Skip to content

Commit f22d1c4

Browse files
author
guohairui
committed
mystack myqueue
1 parent 1a4d174 commit f22d1c4

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 先进先出
3+
*/
4+
public class MyQueue {
5+
private MyLinkedList myLinkedList = new MyLinkedList();
6+
public void enQueue(Object o){
7+
myLinkedList.add(o);
8+
}
9+
public void deQueue(){
10+
myLinkedList.remove(0) ;
11+
}
12+
public boolean isEmpty(){
13+
return myLinkedList.size<1;
14+
}
15+
public int size(){
16+
return myLinkedList.size;
17+
}
18+
public String toString(){
19+
return myLinkedList.toString();
20+
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 先进后出
3+
*/
4+
public class MyStack {
5+
private MyArrayList myArrayList = new MyArrayList();
6+
public MyStack(){}
7+
public void push(Object o) {
8+
myArrayList.add(o);
9+
}
10+
public Object pop(){
11+
Object popo=myArrayList.get(myArrayList.size-1);
12+
myArrayList.remove(myArrayList.size-1);
13+
return popo;
14+
}
15+
public Object peek(){
16+
17+
return myArrayList.get(myArrayList.size-1);
18+
19+
}
20+
public boolean isEmpty(){
21+
22+
return myArrayList.size<1;
23+
}
24+
public int size(){
25+
return myArrayList.size;
26+
}
27+
public String toString(){
28+
return myArrayList.toString();
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.junit.*;
2+
import org.junit.Test;
3+
4+
/**
5+
* Created with IntelliJ IDEA.
6+
* User: guohairui
7+
* Date: 17-2-26
8+
* Time: 下午7:33
9+
* To change this template use File | Settings | File Templates.
10+
*/
11+
public class MyQueueTest {
12+
@org.junit.Test
13+
public void testEnQueue() throws Exception {
14+
MyQueue myQueue=new MyQueue();
15+
myQueue.enQueue("abc1");
16+
myQueue.enQueue("abc2");
17+
myQueue.enQueue("abc3");
18+
System.out.println(myQueue);
19+
myQueue.enQueue("abc4");
20+
System.out.println(myQueue);
21+
myQueue.deQueue();
22+
System.out.println(myQueue);
23+
}
24+
25+
@Test
26+
public void testDeQueue() throws Exception {
27+
28+
}
29+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import org.junit.*;
2+
import org.junit.Test;
3+
4+
/**
5+
* Created with IntelliJ IDEA.
6+
* User: guohairui
7+
* Date: 17-2-26
8+
* Time: 下午7:20
9+
* To change this template use File | Settings | File Templates.
10+
*/
11+
public class MyStackTest {
12+
@org.junit.Test
13+
public void testPush() throws Exception {
14+
MyStack myStack = new MyStack();
15+
myStack.push("abc1");
16+
myStack.push("abc2");
17+
myStack.push("abc3");
18+
System.out.println(myStack);
19+
myStack.push("abc4");
20+
System.out.println(myStack);
21+
System.out.println("myStack.peek:"+myStack.peek());
22+
myStack.pop();
23+
System.out.println("myStack.size"+myStack.size());
24+
System.out.println(myStack);
25+
}
26+
27+
@Test
28+
public void testPop() throws Exception {
29+
30+
}
31+
32+
@Test
33+
public void testPeek() throws Exception {
34+
35+
}
36+
}

0 commit comments

Comments
 (0)