I'm trying to create my own little collection of code that I can basically copy and paste into programs as I need them, but it seems to be causing some problems.
After importing a LinkedList class and a Node class into Netbeans and then changing the constructors a little bit, LinkedList can't seem to find the modified Node constructors. I think it's still trying to find the old constructors, before I modified them.
Here are the two classes. I'm new to using packages; we weren't really taught how to use them, in class. Maybe that's the problem.
The error I get is
"cannot find symbol
symbol : constructor Node(char,int)
location: class vigenerecypher.Node
Node newNode = new Node(data, asciiValue);" on line 24.
Any help would be appreciated.
package vigenerecypher;
public class Node
{
private Node prev;
private Node next;
private char data;
private int asciiValue;
public Node()
{
prev = null;
next = null;
asciiValue = -1;
}
public Node(char data, int asciiValue)
{
this.data = data;
this.asciiValue = asciiValue;
next = null;
prev = null;
}
public Node(Node node)
{
prev = node.prev;
next = node.next;
data = node.data;
asciiValue = node.asciiValue;
}
public Node(char data, int asciiValue, Node prev, Node next)
{
this.data = data;
this.asciiValue = asciiValue;
this.prev = prev;
this.next = next;
}
public Node getPrevious()
{
return prev;
}
public Node getNext()
{
return next;
}
public char getData()
{
return data;
}
public int getAsciiValue()
{
return asciiValue;
}
public void setPrev(Node prev)
{
this.prev = prev;
}
public void setNext(Node next)
{
this.next = next;
}
public void setData(char data)
{
this.data = data;
}
public void setAsciiValue(int asciiValue)
{
this.asciiValue = asciiValue;
}
}
package vigenerecypher;
public class LinkedList
{
Node head = new Node();
Node tail = new Node();
Node current = new Node();
int length;
public LinkedList()
{
head.setNext(tail);
tail.setPrev(head);
current = head;
length = 0;
}
public void addNode(char data, int asciiValue)
{
Node newNode = new Node
newNode.setPrev(tail.getPrevious());
newNode.setNext(tail);
newNode.getPrevious().setNext(newNode);
tail.setPrev(newNode);
length++;
}
public void insertAt(char data, int asciiValue, int position)
{
Node temp = new Node(head.getNext());
for(int x = 0; x < position; x++)
temp = temp.getNext();
if(temp.getAsciiValue == -1)
{
temp.setData(data);
temp.setAsciiValue = asciiValue;
temp.setNext(tail);
tail.setPrev(temp);
}
else
{
temp.setData(data);
temp.setAsciiValue(asciiValue);
temp.setNext(temp.getNext().getPrevious());
temp.getNext().setPrev(temp);
}
temp.getPrevious().setNext(temp);
length++;
}
public int deleteNode(int dataIn)
{
int probes = 0;
current = head.getNext();
while(current.getData()!= dataIn)
{
current = current.getNext();
probes++;
}
probes++;
current.getNext().setPrev(current.getPrevious());
current.getPrevious().setNext(current.getNext());
current = head;
length--;
return probes;
}
}