关于我应该传递给该推送方法的确切内容的问题。我想将一系列 .txt 文件中的信息推送到我的 main 方法内的 wiki 堆栈中,以便我以后可以弹出它并使用它。这是netbeans给我的错误:
没有找到适合 push() 方法的方法 FancyStack.push(FancyStack>) 不适用(实际参数列表和形式参数列表长度不同) 方法 FancyStack.push(Node) 不适用(实际参数列表和形式参数列表长度不同)
如果有人想了解更多信息,请告诉我。
FancyStack<Node<WikiObjects>> wikis = new FancyStack<Node<WikiObjects>>();
FancyStack<Node<WikiObjects>> titles = new FancyStack<Node<WikiObjects>>();
WikiEdits edits = new WikiEdits(args);
String titleName = edits.title();
String editID = edits.editID();
while(edits.moveToNext() != false){
wikis.push();
}
提前致谢!
编辑:这是我的 FancyStack
import java.util.*;
public class FancyStack<E> {
//pieced together linked list
private int cnt;
private Node<E> head;
public FancyStack<E> stack;
public FancyStack<E> s;
public FancyStack() {
head = null;
cnt = 0;
}
public void push(E item) { //THIS WORKS
//your average kind of pushing an item onto stack
Node<E> newNode = new Node<E>(item);
newNode.setLink(head);
head = newNode;
cnt++;
}
public void push(FancyStack<E> s) { //THIS WORKS
//pushes all elements of FancyStack s into a new stack (this)
//however stack this is in reverse order from FancyStack<E> s
if (s.isEmpty()) {
throw new NoSuchElementException("Empty Stack");
}
while (!s.isEmpty()) {
Node<E> element = s.head;
this.push(element.getInfo());
s.pop();
element = element.getLink();
}
}
public boolean isEmpty() {
return head == null;
}
public int size() {
return cnt;
}
public E pop() { //THIS CORRECT
if (isEmpty()) {
throw new NoSuchElementException("Stack underflow");
} else {
E item = head.item;
head = head.link;
cnt--;
return item;
}
}
public E peek() { //THIS WORKS
if (isEmpty()) {
throw new NoSuchElementException("Stack underflow");
}
return head.item;
}
public FancyStack<E> reversed() {
/* if (this.isEmpty()) { // want to test exceotion error with this commented out.
throw new NoSuchElementException("Empty Stack");
}*/
FancyStack<E> newthis = new FancyStack<E>();
while (!this.isEmpty()) { //elmt short for 'element'
Node<E> elmt = this.head;
newthis.push(elmt.getInfo());
this.pop();
elmt = elmt.getLink();
}
return newthis;
}
}