24. Linked List: Basics-1
Basics-
# Intro to Linked List-
1. Here, elements are not in contigous locations.
2. Size of a linked list can be changed at any moment.
3. example of linked list is a browser's forward and backward button.
-------
4. It consists of head, which is 1st node & entry point to a Linked List.
5. Each element stores 2 things- a value & a pointer to the next elmt
-------
6. Elements of a 1D LL only have a next ptr, while 2D LL have both next & prvs ptr...
-----------------------------------------------------------------------------------------------------------------------------
# Pointers-
in 32-bit system, pointer takes 4 bytes
in 64-bit system, pointer takes 8 bytes
-----------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------
# Struct-
a self defined data type...
It needs a constructor to initialise things.
if we use class keyword instead of struct we can use oops concepts as well
We will prefer using dynamic allocation-
-----------------------------------------------------------------------------------------------------------------------------
# Constructors
- they are special functions
- used to initialise objects of the classes
- used to initialise objects of the classes
- we can have multiple constructors
-----------------------------------------------------------------------------------------------------------------------------
1. Converting array to LL-
time: O(n)
------------
------------
for every element-
1. create new node pointing to null
2. point prev node to curr node
3. set prev node pointer to curr node
2. point prev node to curr node
3. set prev node pointer to curr node
mover node is used to move &
temp node is used to create & store new nodes
temp node is used to create & store new nodes
---------------------------------------------------------------------------------------------------------------------------
2. Traversal-
-------------------------------------------------------------------------------------------------------------
3. Length of linked list-
traversal mein ek counter lagado cout se pehle
-------------------------------------------------------------------------------------------------------------
4. Searching for a target node-






Comments
Post a Comment