Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-11-2007, 02:27 AM
Member
 
Join Date: Nov 2007
Posts: 3
jkurth is on a distinguished road
question about linked lists
I would like to start off saying hello, and I also want to apologize if this seems to be a remedial question... I am just drawing a blank, and have been yet to find a solid answer to my question... anyways, I am trying to learn as much as possible about java and I am currently looking into linked list structures in depth, specifically doubly linked lists. I am a little confused as to how the addBefore(position<P> p, Element E) mehtod works. This is the way it is written in my book. Basically, the method is supposed to insert a new node with the data of E before a node p. I am a little confused as to how to reference nodes in a doubly linked list when the node is being refered to by its data (Element). from what I understand, if you have the doubly linked list H<=>1<=>2<=>4<=>t and you call addBefore(4,3), the result should be H<=>1<=>2<=>3<=>4<=>t. This is fine for a sorted list, but what happens if you have multiple nodes with the same data in it? and is that possible? (ie. H<=>2<=>1<=>2<=>t thus when calling the addBefore(2,1) mehtod, 1 would be entered before the first 2, and not the second.)

I guess my basic question is how does the position() mehod work in a unsorted list, and can it work if there is multiple elements in the list with the same data? Any help will be much appreciated. thank you.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-11-2007, 09:33 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
I guess my basic question is how does the position() mehod work in a unsorted list, and can it work if there is multiple elements in the list with the same data?
Looks like you are inserting a value at an index (position) into the list. If this is so then all you care about is that you can find the position, ie, 0 <= position < lastElement. It shouldn't make any difference what the values on either side are or if there are multiple values.
If you were inserting a value after another value (vis-a-vis poisition), ie,
addBefore(Element E_in_list, Element E)
then you would likely insert it before the first instance of the value ("E_in_list") that you find in the list.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 dimensional Lists gapper New To Java 4 01-20-2008 10:01 AM
Tudu Lists 2.1 JavaBean Java Announcements 0 08-10-2007 05:39 PM
Compare lists JavaNoob New To Java 2 08-08-2007 04:11 PM
how to compare 2 vector lists? oregon New To Java 2 07-25-2007 09:25 PM
Tudu Lists 2.0 JavaBean Java Announcements 0 07-11-2007 04:32 PM


All times are GMT +3. The time now is 12:48 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org