This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Linked list problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Linked list problem" Watch "Linked list problem" New topic

Linked list problem

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
It's difficult to tell from your code, but one thing strikes me as incorrect:In Node's constructor, you are ignoring the RuleList that was passed in by the addKeyword method, instead creating an empty list and storing that.
[ September 27, 2004: Message edited by: David Harkness ]
Dominique Ramoney

Joined: Aug 11, 2004
Posts: 25
Thanks David!!

That's exactly what it is. I was just so tired yesterday and I hadn't used a list as a constructor parameter before, I let common sense slip.

Dominique Ramoney

Joined: Aug 11, 2004
Posts: 25

I have a linked list class whose nodes contain a linked list;

I'm doing this like so;

class KeywordList{
private Node head;

public KeywordList() {
head = null;

public void addKeyword(String newrule) {
Node current,previous,newNode;
(initialize stuff here)
RuleList rule = new RuleList();
(use a method here from RuleList to add to Rule List)
newNode = new Node(newkey, rule, current);


class Node {
String keyword;
int occurrences;
Node next;
RuleList rule;

Node(String newkey, RuleList rule, Node newLink) {
keyword = new String(newkey);
rule = new RuleList();
occurrences = 1;
next = newLink;

public void display(){

RuleList.Iterator RuleRetriever = Iterator();
System.out.println("Keyword " + keyword);
while (RuleRetriever.hasMoreRules()) {
System.out.print("from display ");

(methods for Node class follows and Iterator class)

The problem I'm having is that I am unable to access the rule parameter of Node from the display method. My toString method and compareTo method has no problem getting keyword or occurrences but trying to access the rule, yields null.

This is really making my brain bleed. Any help will go long way in avoiding an aneurisym.


Vladas Razas
Ranch Hand

Joined: Dec 02, 2003
Posts: 385
As much as I would love to help you but your question is not formed well. It has code that do not pertain directly to the question. Please write us what specificaly doesn't work.
I agree. Here's the link:
subject: Linked list problem
It's not a secret anymore!