• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

LinkedList  RSS feed

 
Ranch Hand
Posts: 509
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The elements in a LinkedList are doubly linked to each other? what does it mean?
 
Sheriff
Posts: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
ok..thanks...i got it.
 
Marshal
Posts: 60879
190
  • Mark post as helpful
  • send pies
  • 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: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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 ...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!