This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to "Walk Through" SinglyLinkedLists  RSS feed

 
Jose Castillo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a summer class, I am building a "bag" from a singly linked list. One of the functions of this linkedbag class is checking to see if the list contains an element, and the frequency of elements. Coming into this, I thought I ought to be able to just use .getNext() and .getElement() to iterate through the linkedlist. However, I am getting "Cannot find Symbol: getNext()", despite it being a part of my SinglyLinkedList class.

When I do SLL.head.getNext/getElement, it works. I am thinking I am making a silly little mistake. Here are my classes so far:

Here's my SinglyLinkedList class:
http://pastebin.com/YJUF7gZ8
Here's my LinkedBag class (So far):
http://pastebin.com/feD3uHCT
Here's my Bag Interface:
http://pastebin.com/naMXf4Gs


Edit:
oh, silly me, I figured it out. You have to call next on individual nodes, not just on the linked list itself.
 
Tim Cooke
Marshal
Posts: 3872
233
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you got it sorted out.

For future reference, it is preferred that you paste your code directly into your forum questions and Use Code Tags to make it format nicely. Links off to other sites are not recommended as a lot of people, such as myself, will simply not bother thus reducing the chance that you will receive any help for your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!