I have 2 questions about linked lists so i figured i'll post them in one question.
first i'll show my node class and the copy constructor and constructor from a string
class CharNode
{
private char letter;
private CharNode next;
public CharNode(char ch, CharNode link)
{
letter = ch;
next = link;
}
public void setCharacter(char ch)
{
letter = ch;
}
public char getCharacter()
{
return letter;
}
public void setNext(CharNode next)
{
this.next = next;
}
public CharNode getNext()
{
return next;
}
}
copy constructor
// copy constructor
public CharList(CharList l)
{
CharNode pt = head;
while(pt.getNext() != null)
{
this.setCharacter() = l.getCharacter();
this.setNext() = l.getNext();
}
}
constructor from string
// constructor from a String
public CharList(String s)
{
head = head.setCharacter(s);
}
when i try to compile i get an error for my copy constructor it says that it cant find the symbol this.setCharacter()... and the l.setCharacter()...
am i just doing it completely wrong?
and with my constructor from a string i know thats wrong. i thought about using the charAt() but how would i know when to stop the loop to do that? is that a good approach to take?
any help would be appreciated.