Prateek sir here had mentioned that lists cannot be accessed by square brackets but in the List STL example video, “[ ]” has been used. Also explain why we cannot use it
Doubt : List STL Example
actually we made an array of list when we performed following operation
list<pair<int,int> > *l ;
l=new list<pair<int,int>[n] (here we dynammicaly allocated an array of list)
so when we do l[x] we access xth list in the array of list l
In case of any doubt feel free to ask
Mark your doubt as resolved if you got your answer
Didn’t get you…are you saying that [ ] can be used for list of array…also isn’t this list of arrays rather than arrays of list?
let me explain you by example :-
when you have
int a[1000];
then a is array of integers
now replace int with list (as list is also a datatype)
we get
list < int> a[1000] ;
now a is array of list
when you do int *l;
l=new int[n] here you dynammically allocate array of int
similarly if you have list *l
l= new list< int >[n] you decide what to call a dynamically allocated array of list or list of array
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.