Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Luke Gotto
Greenhorn
+ Follow
2
Posts
2
Threads
0
Cows
since Apr 04, 2008
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
Ranch Hand Scavenger Hunt
Number Posts (2/100)
Number Threads Started (2/100)
Number Cows Received (0/5)
Number Likes Received (0/10)
Number Likes Granted (0/20)
Set bumper stickers in profile (0/3)
Report a post to the moderators (0/1)
Edit a wiki page (0/1)
Create a post with an image (0/2)
Greenhorn Scavenger Hunt
First Post
Number Posts (2/10)
Number Threads Started (2/10)
Number Likes Received (0/3)
Number Likes Granted (0/3)
Set bumper stickers in profile (0/1)
Set signature in profile
Search for a post/thread (0/3)
Set a watch on a thread
Save thread as a bookmark
Create a post with an image (0/1)
Recent posts by Luke Gotto
Linked List Remove?
When i run this it removes all of the elemets of the list except the last one... Any ideas why it is not geting to the last node?
public E remove() // delete link with given key
{
E tmp;
tmp = null;
cursor = first;
previous = first;
if (cursor == null)
return null;
else
tmp = first.item;
previous = cursor;
first = cursor.next;
length = length -1;
return tmp;
}
show more
15 years ago
Beginning Java
Need help to convert from Con List to Link List
package Collections; import java.io.*; import java.util.*; /** This class represents an implementation of the List interface using contiguous * storage (array). * * @see List * @see Keyed * @see NoSpaceException * @see NoItemException */ public class ConList < E extends Keyed > implements List<E>, Serializable { E[] items; // the items in the list int cursor; // the list cursor int length; // the length of the list /** This constructor creates a new empty list capable of holding 100 items. */ public ConList ( ) { this(100); }; // constructor /** This constructor creates a new empty list capable of holding a specified * number of items. * * @param size the maximum size of the list. */ public ConList ( int size ) { items = (E[]) new Keyed[size]; cursor = 0; length = 0; }; // Constructor /** This method returns an interator that iterates through the list from the * front as requried by Iterable<E>. * * @return Iterator<E> an iterator on the list. */ public Iterator<E> iterator ( ) { return new ConListIterator<E>(this); }; // iterator /** This method adds an item to the list in front of the cursor. If the cursor * is off the end of the list, the insertion is at the end of the list. The * cursor references the item just added. ListOverflow occurs if there is no * room to add another item. * * @param item the item to be added. * * @exception NoSpaceException no more room to add items. */ public void add ( E item ) { int j; if ( length >= items.length ) { throw new NoSpaceException(); } else { for ( j = length-1 ; j>=cursor ; j-- ) { items[j+1] = items[j]; }; items[cursor] = item; length = length + 1; }; }; // add /** This method removes the item at the cursor from the list. The cursor * references the item following the one removed. A NoItemException occurs if * the cursor was off the end of the list. * * @result E the item removed. * * @exception NoItemException no current item (cursor off list). */ public E remove ( ) { E i; int j; if ( cursor >= length ) { throw new NoItemException(); } else { i = items[cursor]; for ( j=cursor+1 ; j<length ; j++ ) { items[j-1] = items[j]; }; length = length-1; items[length] = null; return i; } }; // remove /** This method returns the item at the cursor. A NoItemException occurs if the * cursor was off the end of the list. * * @result E the item at the cursor. * * @exception NoItemException no current item (cursor off list). */ public E get ( ) { if ( cursor >= length ) { throw new NoItemException(); } else { return items[cursor]; } }; // get /** This method returns true if the list has no items. * * @return boolean the list has no items. */ public boolean empty ( ) { return length == 0; }; // empty /** This method returns the number of items in the list. * * @result int the number of items in the list. */ public int length ( ) { return length; }; // length /** This method moves the cursor to the first item on the list. If the list is * empty, the cursor will be off the end of the list. */ public void toFront ( ) { cursor = 0; }; // toFront /** This method advances the cursor to the next item in the list. If the cursor * was off the list, it remains off the list. */ public void advance( ) { if ( cursor < length ) { cursor = cursor + 1; }; }; // advance /** This method advances the cursor to the next item, starting from the cursor, * that matches the specified key. If there is no such entry, the cursor is * moved off the end of the list. * * @param key the key for matching in the search. */ public void find ( String key ) { while ( cursor < length && key.compareTo(items[cursor].getKey()) != 0 ) { cursor = cursor + 1; }; }; // find /** This method indicates if the cursor is off the end of the list. * * @return boolean the cursor is off the end of the list. */ public boolean offEnd ( ) { return cursor >= length; }; // offEnd } // ConList
[ April 04, 2008: Message edited by: Fred Rosenberger ]
show more
15 years ago
Beginning Java