• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Linked list problem

 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Dominique Ramoney
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

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);
newNode.display();

}

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 = rule.new Iterator();
System.out.println("Keyword " + keyword);
while (RuleRetriever.hasMoreRules()) {
System.out.print("from display ");
System.out.println(String.valueOf(RuleRetriever.nextItem()));}
}


(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.

Thanks
Dominique

 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 found some pretty shells, some sea glass and this lovely tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic