java中类和接口实现的问题
1. 编写实现接口Srack的类ArrayStack,以完成基于顺序存储(数组)结构的栈数据结构,并编写主类进行测试。2. 编写实现接口Srack的类LinkedStack,以完成基于链式存储结构的栈数据结构,并编写主类进行测试。
小弟刚刚学习java,请大神详解 java 类 --------------------编程问答-------------------- 应该是stack ,不是srack
实现接口的话 用implements 关键字 --------------------编程问答-------------------- 说你哪不明白? --------------------编程问答-------------------- 都不明白,这到底是要我们自己实现Stack 中ArrayStack的功能还是怎么回事、、?如果是这样,该如何实现?所提供的参考如下:
ListNode.java
/** Node in a linked list. */
public class ListNode<E> {
/** The item stored in this node. */
private E item;
/** The node following this one. */
private ListNode<E> next;
/** Put item in a node with no next node. */
public ListNode(E item) {
this.item = item;
next = null;
}
/** Put item in a node with the specified next node. */
public ListNode(E item, ListNode<E> next) {
this.item = item;
this.next = next;
}
/** Return the item stored in this node. */
public E getItem() {
return item;
}
/** Return the next node. */
public ListNode<E> getNext() {
return next;
}
/** Replace the item stored in this node. */
public void setItem(E item) {
this.item = item;
}
}
Stack.java
/** A last-in, first-out stack. */
public inte易做图ce Stack<E> {
/** Return true if this Stack is empty. */
public boolean isEmpty();
/**
* Return the top item on this Stack, but do not modify the Stack.
* @throws EmptyStructureException if this Stack is empty.
*/
public E peek();
/**
* Remove and return the top item on this Stack.
* @throws EmptyStructureException if this Stack is empty.
*/
public E pop();
/** Add targer to the top of this Stack. */
public void push(E target);
}
补充:Java , Java相关