Results 1 to 6 of 6
  1. #1
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default SLLIstIter inner Help

    Hey guys,

    I need help very badly in this java program. I need to hand it in a day and i cant solve this yet.

    I have done the layout alraedy but cant seem to implement it, my Code is posted below. I even put notes in there on what i have to do but cant.

    Heres what i need help in:

    1) I need to rename SLListPartial to SLList and complete it by writing code for the methods that are stubs. I cant use private methods such as addFirst, addAfter, getNode

    2)I also need to write a SLLIstIter inner class for SLList. This class should implement Iterator, not ListIterator. Im try to write methods hasNext, next, and remove for this class but its been to confusing.

    Me and my friend start the program, I am good at writing layouts but Couldnt get the rest. He didnt no anythin either.


    Heres what i have wrote so far:

    Java Code:
    package singlelinkedlist;
    
    import java.util.*;
    
    /**
     *
     * @author Owner
     */
    public class SLListPartial<E> extends AbstractList<E> implements List<E> {
       /** data fields */
      Node<E> head = null;
      int size = 0;
    
    
    private static class Node<E> {
      private E data;
      private Node<E> next;
    
      private Node (E data, Node<E> node) {
        this.data = data;
        this.next = node;
      }
    
      private Node (E data) {
        this(data, (Node<E>)null);
      }
    }
    
    @Override
    public int size() {
      // change this
      return 0;
    }
    
    @Override
    public int indexOf(Object obj) {
        /**  do this one.  Hint: To compare obj with the item referenced by
         *   temp, use the following code:
         * if (temp.data.getClass() == obj.getClass() &&
                temp.data.equals( (E) obj)) {
                return cursor;
            }
         */
    
        return -1;
    }
    
    @Override
    public void add(int index, E item) {
    
    // This is the following hints i have recieved but doesnt help me
    // Do this without using getNode, addFirst, or addLast
    /**  algorithm
    1.  if index is not valid (too small or too big) throw an exception
    2.  Set temp to head and i to 0 
    3.  while i is less than index-1
            Advance temp down the list and increment i 
    4.  if index is 0
           insert at list head so head points to a new node
        else
           Insert a new node between temp and temp's successor
    5.  Increment size
    */
    
    }
    
    @Override
    public boolean add(E item) {
      // Hint: Use add(int index, E item)
    
    
        return true;
    }
    
    
    
    @Override
    public E get(int index) {
       // Do this one without using getNode
    
        
        return null;
    }
    
    @Override
    public Iterator<E> iterator() {
        return new SLListIter();
    }
    
    private class SLListIter implements Iterator<E> {
       private Node<E> prevItem = null;
       private Node<E> nextItem = null;
       private Node<E> lastItemReturned = null;
    
       public SLListIter() {
           // I need to fill this in
       }
    
       @Override
       public boolean hasNext() {
           return true;   //  I need to change this
       }
    
       @Override
       public E next() {
          return null;  //  I need to change this
       }
    
       @Override
       public void remove() {
           // I need to change this
       }
    }
    
    }



    Thank You so much.
    Last edited by acash229; 09-24-2010 at 01:48 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by acash229 View Post
    I need help very badly in this java program. I need to hand it in a day and i cant solve this yet.
    To quote the How to Ask Smart Questions site: That's your problem, not ours. Claiming urgency is very likely to be counter-productive: most hackers will simply delete such messages as rude and selfish attempts to elicit immediate and special attention.

    Heres what i need help in:

    1) I need to rename SLListPartial to SLList and complete it by writing code for the methods that are stubs. I cant use private methods such as addFirst, addAfter, getNode

    2)I also need to write a SLLIstIter inner class for SLList. This class should implement Iterator, not ListIterator. Im try to write methods hasNext, next, and remove for this class but its been to confusing.
    Please at least show us what you've tried for these problems above first, otherwise we've no idea what you're stuck on and you just appear to be dumping homework on us.

    Heres what i have wrote so far:
    //.... bunch of unformatted code
    If you want folks to read your code, please use code tags on formatted code so that it's readable.

    Much luck.

    EDIT:
    Your most recent post:
    Quote Originally Posted by acash229 View Post
    Hey guys,

    I need help very badly in this java program. I need to hand it in a day and i cant solve this yet.

    I have done the layout alraedy but cant seem to implement it, my Code is posted below. I even put notes in there on what i have to do but cant.

    Heres what i need help in:

    1) I need to rename SLListPartial to SLList and complete it by writing code for the methods that are stubs. I cant use private methods such as addFirst, addAfter, getNode

    2)I also need to write a SLLIstIter inner class for SLList. This class should implement Iterator, not ListIterator. Im try to write methods hasNext, next, and remove for this class but its been to confusing.

    Me and my friend start the program, I am good at writing layouts but Couldnt get the rest. He didnt no anythin either.

    Heres what i have wrote so far:

    Java Code:
    package singlelinkedlist;
    
    import java.util.*;
    
    /**
     *
     * @author Owner
     */
    public class SLListPartial<E> extends AbstractList<E> implements List<E> {
       /** data fields */
      Node<E> head = null;
      int size = 0;
    
    
    private static class Node<E> {
      private E data;
      private Node<E> next;
    
      private Node (E data, Node<E> node) {
        this.data = data;
        this.next = node;
      }
    
      private Node (E data) {
        this(data, (Node<E>)null);
      }
    }
    
    @Override
    public int size() {
      // change this
      return 0;
    }
    
    @Override
    public int indexOf(Object obj) {
        /**  do this one.  Hint: To compare obj with the item referenced by
         *   temp, use the following code:
         * if (temp.data.getClass() == obj.getClass() &&
                temp.data.equals( (E) obj)) {
                return cursor;
            }
         */
    
        return -1;
    }
    
    @Override
    public void add(int index, E item) {
    
    // This is the following hints i have recieved but doesnt help me
    // Do this without using getNode, addFirst, or addLast
    /**  algorithm
    1.  if index is not valid (too small or too big) throw an exception
    2.  Set temp to head and i to 0 
    3.  while i is less than index-1
            Advance temp down the list and increment i 
    4.  if index is 0
           insert at list head so head points to a new node
        else
           Insert a new node between temp and temp's successor
    5.  Increment size
    */
    
    }
    
    @Override
    public boolean add(E item) {
      // Hint: Use add(int index, E item)
    
    
        return true;
    }
    
    
    
    @Override
    public E get(int index) {
       // Do this one without using getNode
    
        
        return null;
    }
    
    @Override
    public Iterator<E> iterator() {
        return new SLListIter();
    }
    
    private class SLListIter implements Iterator<E> {
       private Node<E> prevItem = null;
       private Node<E> nextItem = null;
       private Node<E> lastItemReturned = null;
    
       public SLListIter() {
           // I need to fill this in
       }
    
       @Override
       public boolean hasNext() {
           return true;   //  I need to change this
       }
    
       @Override
       public E next() {
          return null;  //  I need to change this
       }
    
       @Override
       public void remove() {
           // I need to change this
       }
    }
    
    }
    Thank You so much.

    I see that you've fixed the code tag issue but have not shown any more recent fruits of your effort. Again, I urge you to please show us that you're at least trying to solve this on your own and what the results of this effort has been.
    Last edited by Fubarable; 09-24-2010 at 02:37 PM. Reason: Checking for evidence of effort from the original poster

  3. #3
    ronak12 is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    It looks like he did the frame good

  4. #4
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    Like he said i did the frame good, so can you please help with the middle part

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ronak12 View Post
    It looks like he did the frame good
    Quote Originally Posted by acash229 View Post
    Like he said i did the frame good, so can you please help with the middle part

    Of course he said you've done good work. ;)
    Just so all know: ronak12 and acash229 are one and the same person. Too funny.

    To acash229: the invitation is still open for you to show us your work on your problem at hand. Surely after more than a day, you've tried to do some work on this on your own, right? So feel free to post for us the results of your latest efforts.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Ah, cross-posted here as well:
    Lister help in java (Please Help) - Dev Shed

    and here as well which appears to have been locked:
    http://www.javaprogrammingforums.com...nner-help.html

    Time to end this homework dump charade and lock this thread. If anyone has strong objection, please feel free to private message me.
    Last edited by Fubarable; 09-25-2010 at 03:24 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •