24. Linked List-1: construction | traversal
Basics-
1) Intro to LL-
in a LL, elmts are not in contigous locations
size can be changed at any moment...
example of linked list usage is a browser's fwd & back btn...
LL consists of head and tail
each elmt stores 2 things- data & a pointer to the next elmt
elements of a 1D LL only have a next ptr, while 2D LL have both next & prvs ptr...
-----------------------------------------------------------------
2) Pointers-
in 32-bit sys pointer takes 4 bytes
in 64-bit sys pointer takes 8 bytes
--------------------------------------------------------------------
--------------------------------------------------------------------
3) Struct-
a self defined data type...
It needs a constructor to initialize things at first.
if we use class keyword instead of struct we can use oops concepts as well
4) Constructors
special functions which are used to initialize objects of the classes
we can have multiple constructors
-----------------------------------------------------------------------------------------------------------------------------
1. Converting array to LL- O(n)
for every element-
1. create new node pointing to null
2. point prev node to curr node
3. move prev node to curr node
2. point prev node to curr node
3. move prev node to curr node
mover node used to move & temp node used to create & store new nodes
---------------------------------------------------------------------------------------------------------------------------
2. Traversal-
-------------------------------------------------------------------------------------------------------------
3. Length of linked list-
traversal mein ek counter lagado cout se pehle
-------------------------------------------------------------------------------------------------------------
4. Searching- O(n)







Comments
Post a Comment