Results 1 to 4 of 4
- 03-23-2011, 01:52 AM #1
Member
- Join Date
- Aug 2010
- Location
- US
- Posts
- 4
- Rep Power
- 0
Problem with ToString list (java)
i am a hard time for the toString in this program
Java Code:public class SpecializedList implements SpecializedListInterface { protected class SListNode // List nodes for the specialized list implementation { protected byte info; // The info in a list node protected SListNode next; // A link to the next node on the list protected SListNode back; // A link to the previous node on the list } protected SListNode listFirst; // Reference to the first node on list protected SListNode listLast; // Reference to the last node on the list protected int numElements; // Number of elements in the list protected SListNode currentFPos; // Current forward position for iteration protected SListNode currentBPos; // Current backward position for iteration public SpecializedList() // Creates an empty list object { numElements = 0; listFirst = null; listLast = null; currentFPos = null; currentBPos = null; } public int size() // Determines the number of elements on this list { return numElements; } public void resetForward() // Initializes current forward position for an iteration through this list { currentFPos = listFirst; } public byte getNextElement () // Returns the value of the next element in list in forward iteration { byte nextElementInfo = currentFPos.info; if (currentFPos == listLast) currentFPos = listFirst; else currentFPos = currentFPos.next; return nextElementInfo; } public void resetBackward() // Initializes current backward position for an iteration through this list { currentBPos = listLast; } public byte getPriorElement () // Returns the value of the next element in list in backward iteration { byte nextElementInfo = currentBPos.info; if (currentBPos == listFirst) currentBPos = listLast; else currentBPos = currentBPos.back; return nextElementInfo; } public void addFront (byte element) // Adds the value of element to the beginning of this list { SListNode newNode = new SListNode(); // Reference to node being added newNode.info = element; newNode.next = listFirst; newNode.back = null; if (listFirst == null) // Adding into an empty list { listFirst = newNode; listLast = newNode; } else // Adding into a non-empty list { listFirst.back = newNode; listFirst = newNode; } numElements++; } public void addEnd (byte element) // Adds the value of element to the end of this list { SListNode newNode = new SListNode(); // Reference to node being added newNode.info = element; newNode.next = null; newNode.back = listLast; if (listFirst == null) // Adding into an empty list { listFirst = newNode; listLast = newNode; } else // Adding into a non-empty list { listLast.next = newNode; listLast = newNode; } numElements++; } public String toString () { String listString = " List: \n"; SListNode current = listFirst; while (current != null) { listString += current; current = current.back; } return listString; } }
-
- 03-23-2011, 02:00 AM #3
Member
- Join Date
- Aug 2010
- Location
- US
- Posts
- 4
- Rep Power
- 0
i am trying to print out the item in my list but instead i get the addresses printed out
- 03-23-2011, 02:02 AM #4
Similar Threads
-
java problem with list
By mike_ledis in forum AWT / SwingReplies: 3Last Post: 03-13-2011, 01:40 PM -
how to create list of list in java ???
By ilayaraja in forum Advanced JavaReplies: 1Last Post: 10-26-2009, 04:30 PM -
Abstract, toString, inherits Class & other Problem !
By tking88 in forum New To JavaReplies: 2Last Post: 10-23-2009, 02:48 AM -
toString() method of java.security.MessageDigest
By Nicholas Jordan in forum Advanced JavaReplies: 4Last Post: 09-18-2008, 02:32 PM -
problem with super.tostring()
By faw in forum Advanced JavaReplies: 1Last Post: 05-01-2008, 04:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks