I'm trying to do the following using a linked list.
delete("is",2)
print 1:This 2:is 3:an 4:an 5:icorrect 6:sntence
delete("an",3)
print 1:This 2:is 3:an 4:icorrect 5:sntence
delete("icorrect",4)
print 1:This 2:is 3:an 4:sntence
insert("incorrect",4)
print 1:This 2:is 3:an 4:incorrect 5:sntence
delete("sntence",5)
insert("sentence",5)
print 1:This 2:is 3:an 4:incorrect 5:sentence
neighbors("is") 2:is previous:This next:an
It's like a sentence editor. It follows the commands on the left side ( print, delete, insert) etc. so that "This is is an an icorrect sntence." becomes "This is an incorrect sentence."
Using fstream to read the text file this is from and load it into the nodes. Each word in a seperate node. I have no idea how to build this linked list. The book only talks about deleting first node, deleting last node, retrieve data from first node etc. But that is not what I am looking for, I think.
Would this do it?
public class SLinkedList {
protected Node head; // head node of the list
/** Default constructor that creates an empty list */
public SLinkedList() {
head = null;
}
// ... update and search methods would go here ...
}
I have been trying forever to figure this out. Help is really appreciated!!