hasNext() in Java

hasNext() for ListIterator

Page 1 of 1

1 Replies - 4590 Views - Last Post: 13 March 2008 - 11:48 PM Rate Topic: -----

#1 kalynel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-December 07

hasNext() in Java

Posted 13 March 2008 - 10:54 PM

I am trying to implement a double-linked list, with a ListIterator, I am looking for examples to compare my code to but can't seem to find anything that works the way I need it to. Here is what I have so far for the MyIterator class. But can anyone lead me in the right direction for the hasNext() method???

Thanks
   private class MyIterator
            implements ListIterator<E>
    {

        /**
         * Current node pointed to by iterator
         */
        private MyNode current;
        /**
         * Previous node pointed to by iterator
         */
        private MyNode lastNode;
        /**
         * Indicates if node can be removed
         */
        private boolean canRemove;
        /**
         * 
         * Constructor for the MyIterator class.
         */
        public MyIterator()
        {
            current = head;
            lastNode = null;
            canRemove = false;
        }
        public MyIterator(MyNode startingNode)
        {
            //lastNode = startingNode;
            current = startingNode;
            
            current = startingNode.next;
        }
        
        public boolean hasPrevious()
        {
            return lastNode != null;
        }
        public int previousIndex()
        {
            int index = 0;
            return index;
        }
/**
         * Purpose:  Determines if there is another node after
         * the current one
         * @return true if there is a next node, false otherwise
         */
        public boolean hasNext()
        {
            boolean result = false;
            if(current == null)
            {
                result = false;
            }
            else
            {
                result = true;
            }
            return result;
        }



1lacca: added code tags

Is This A Good Question/Topic? 0
  • +

Replies To: hasNext() in Java

#2 bhandari  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Re: hasNext() in Java

Posted 13 March 2008 - 11:48 PM

can u please edit your post and :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1