下一页 1 2 3
现在对C++学习了一段时间,把C++的特性和Java做比较有很强烈的快感:P
自己写了两个版本的Stack:
Java版本:
源代码Stack.java
package org;
public class Stack ...{
public static class Link ...{
protected Object data;
protected Link next;
public Link(Object data, Link next) ...{
this.data = data;
this.next = next;
}
}
private Link head = null;
public void push(Object data) ...{
head = new Link(data, head);
}
public Object peek() ...{
return head.data;
}
public Object pop() ...{
if (head == null)
return null;
Object o = head.data;
head = head.next;
return o;
}
} 测试代码StackTest.java
package org;
import junit.framework.TestCase;
public class StackTest extends TestCase ...{
public void test1() ...{
Stack s = new Stack();
assertEquals(null, s.pop());