• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question about linked list  RSS feed

 
Dan D'amico
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if one address point on another address. so set and get methods will be less efficient then an array, but add or remove will be more efficient by a linked list ?

a linked list also inherit from queue so if i add an elemnt via "addFirst" function . where its adding the element ? to the right most or left most ?
if i have for example :

here [ ] --> [ ] --> [ ] --> [ ] -->[ ] or here

linked list its FIFO so the head will be the right most ?

Edit : its confused me a little bit but i understood now .
so it will be at the left most. its actually ordered . not like the stack which is LIFO.

 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lists and stacks both follow insertion order, but when a list is used as a Queue is it FIFO and when it is used as a stack it is LIFO.
Yes, in your diagram addFirst would add to the left.
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe someone should write a book called, "Ask Java."

The answer to this question can be inferred from the behavior of a simple Java program:



Output is this:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!