• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LinkedList

 
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The elements in a LinkedList are doubly linked to each other? what does it mean?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means each element has a reference to two other elements. The first one is the element before the current element and the second is the element after the current element...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each element in the linked list will have three parts
First part stores the reference to previous element
Second stores the data
and
Third stores reference to next element

Such a linked list which stores reference of both previous and next element, at each element is known as a doubly linked list.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is said because ArrayList is faster than LinkedList in traversal but ArrayList is very slow in insertion and deletion...
 
Abhi vijay
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..thanks...i got it.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ankit Garg:
This is said because ArrayList is faster than LinkedList in traversal but ArrayList is very slow in insertion and deletion...



Bit of an exaggeration to say ArrayList is very slow in insertion and deletion. Slower than a LinkedList, yes, but not very slow.
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
Bit of an exaggeration to say ArrayList is very slow in insertion and deletion. Slower than a LinkedList, yes, but not very slow.



Yup. You are right. When we add or delete elements to it, then we don't even realize it.

But there is a reason why I said it. ArrayList is slower than LinkedList but HashMap is faster than LinkedHashMap in insertion and deletion. So in the beginning I used to get confused between these as one of the Linked collection is fast and one is slow. So I memorized it by thinking that ArrayList is very slow, Linked collections are fast but HashMap is ultra fast. So the statement came out of mind out of intuition ...
 
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic