推送到java中使用链表的堆栈
关于我到底应该把什么传递到那个推送方法中的问题。我想将一系列.txt文件中的信息推送到我的main方法中的wiki堆栈中,以便以后可以将其弹出并使用它。以下是netbeans给我的错误: 未找到适用于push()的方法 方法FancyStack.push(FancyStack>)不适用 (实际参数列表和正式参数列表长度不同) 方法FancyStack.push(节点)不适用 (实际参数列表和正式参数列表长度不同) 如果有人想了解更多信息,请告诉我推送到java中使用链表的堆栈,java,linked-list,stack,push,Java,Linked List,Stack,Push,关于我到底应该把什么传递到那个推送方法中的问题。我想将一系列.txt文件中的信息推送到我的main方法中的wiki堆栈中,以便以后可以将其弹出并使用它。以下是netbeans给我的错误: 未找到适用于push()的方法 方法FancyStack.push(FancyStack>)不适用 (实际参数列表和正式参数列表长度不同) 方法FancyStack.push(节点)不适用 (实际参数列表和正式参数列表长度不同) 如果有人想了解更多信息,请告诉我 FancyStack<Node<Wi
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();
}
fancystackwiki=new FancyStack();
FancyStack titles=新的FancyStack();
WikiEdits=新的WikiEdits(args);
字符串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;
}
import java.util.*;
公共级FancyStack{
//拼凑链表
私人互联网;
专用节点头;
公共FancyStack堆栈;
公众爱好者;
公共FancyStack(){
head=null;
cnt=0;
}
公共无效推送(E项){//此项有效
//您将一个项目推到堆栈上的平均类型
节点newNode=新节点(项);
newNode.setLink(head);
头=新节点;
cnt++;
}
公共无效推送(FancyStack s){//此操作有效
//将FancyStack s的所有元素推入新堆栈(此)
//然而,这与FancyStack s的顺序相反
如果(s.isEmpty()){
抛出新的NoSuchElementException(“空堆栈”);
}
而(!s.isEmpty()){
节点元素=s.head;
this.push(element.getInfo());
s、 pop();
element=element.getLink();
}
}
公共布尔值为空(){
返回头==null;
}
公共整数大小(){
返回cnt;
}
public E pop(){//这是正确的吗
if(isEmpty()){
抛出新的NoTouchElementException(“堆栈下溢”);
}否则{
E项目=总目。项目;
head=head.link;
碳纳米管;
退货项目;
}
}
public E peek(){//这很有效
if(isEmpty()){
抛出新的NoTouchElementException(“堆栈下溢”);
}
返回head.item;
}
公共FancyStack反向(){
/*如果(this.isEmpty()){//要用注释掉的内容测试例外错误。
抛出新的NoSuchElementException(“空堆栈”);
}*/
FancyStack newthis=新的FancyStack();
而(!this.isEmpty()){//elmt是'element'的缩写
节点elmt=this.head;
newthis.push(elmt.getInfo());
这个。pop();
elmt=elmt.getLink();
}
返回newthis;
}
}您已指定
wikis
是节点
对象的FancyStack
。必须推送节点
对象FancyStack
还允许您推送另一个FancyStack
。在我看来,这是一个命名不好的API,因为它没有做到它所说的。它不推送FancyStack
,而是推送FancyStack
中的所有元素。它应该命名为pushAll
根据提供的FancyStack源进行编辑是有意义的。非常感谢。