• 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

Problem With Linked List

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone. I have a problem with a linked list program I am currently working on. In the main body, a word is entered at a time. The word is then stored into a node and inserted alphabetically in its place. I am current getting all sorts of null pointer exceptions, so I was wondering if anyone could take a look at this and see what it is that I am doing wrong (btw - this needs to be done using a linked list).
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-If your head node isn't a dummy node, remember to check and make sure your new node isn't supposed to be the new head.
-Please consider renaming "word" to something like "newNode" because "word" sounds like a String, not a ListNode.
Try making your logic plainer by creating a couple booleans named such that it is clear what you are testing.
You might re-name your ListNodes x and y something like currentNode and nextNode, then drawn a picture of what happens as the method executes.
What you want to do is

[ March 12, 2004: Message edited by: Elouise Kivineva ]
 
Lionel Goodheart
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay I worked out the method, and it work fine except for one reason. The second word that is entered ALWAYS ends up going to the end of the list. (For those unfamiliar with the program, read the first paragraph of the first post). Anyone know what could possibly be wrong with this?
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic