Simple linked list demos

H

Heather B

hi there,

i am taking a data structures class taught in java, and i am looking for
some example code to help me learn about linked lists by seeing an
assortment of implementations. can anyone either post or email me some
examples of basic linked list implementations?

thanks much,
heather
 
B

Brad BARCLAY

Heather said:
i am taking a data structures class taught in java, and i am looking for
some example code to help me learn about linked lists by seeing an
assortment of implementations. can anyone either post or email me some
examples of basic linked list implementations?

There are many different types of linked-list. There are one-way
lists, two-way lists, and circular lists. Some lists will have
dedicated start and end elements, others don't.

The most basic linked-list structure in Java would be the following class:

public class LinkedListElement {
public LinkedListElement next;
public Object data;
}

That's about as basic as you can get for a one-way list. Chances are,
however, you'll want to add some methods to do common tasks like get and
set the data value, insert a node after this one, etc.

You can also add a second "prev" pointer element of LinkedListElement
type for a two-way list, that can be easily traversed in either
direction. Either type can be made circular, by having the last
element's next field point to the first element.

As you're doing this for a class, I'll leave it to you to take care of
implementing the rest. HTH!

Brad BARCLAY
 
R

Roedy Green

i am taking a data structures class taught in java, and i am looking for
some example code to help me learn about linked lists by seeing an
assortment of implementations. can anyone either post or email me some
examples of basic linked list implementations?

There is java.util.LinkedList You can see source is src.zip.

I wrote one before it became available. See
http://mindprod.com/products.html#LINKEDLIST
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linked lists 73
linked list 3
linked list example 34
Reversing a linked list 116
linked list implementation 7
Singly Linked List in C 62
Looking to change programming direction 1
doubly-linked list & sorting 5

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top