Pages

Linked List

What is Linked List?
  • The underlying data structure is doubly linked list
  • Insertion order is preserved 
  • Duplicate objects are allowed
  • Heterogeneous objects are allowed
  • null insertion is possible
  • Linked list implements Serializable and cloneable interfaces but not random access
  • A linked list is the best choice if the ever frequent operation is insertion or deletion in the middle
  • A linked list is the worst choice if the ever frequent operation is retrieval operation
Constructors::

1) LinkedList l=new LinkedList(); ---->  creates an empty linked object
2) LinkedList l=new LinkedList(Collection c); ----> creates an equivalent linked list object for the given collection.

---> Usually we can use linked lists to develop stacks and queues.To provide support for these requirement linked list class defines the following specific methods::

  1. void addFirst(Object o)
  2. void addLast(Object o)
  3. Object getFirst()
  4. Object getLast()
  5. Object removeFirst()
  6. Object removeLast()
Key Points:
  • LinkedList  is the best choice if ever frequent operation is insertion/deletion in the middle
  • LinkedList is the worst choice if ever frequent operation is retrieval operation
  • In LinkedList, the elements won't be stored in consecutive memory locations and hence retrieval operation will become difficult
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.