If you are using STL fist time , you can see that these are the classes for holding a gropup of things.
You need to
include #include <vector> and #include <list> for using
these classes, also specify they are in std namespace . This can be
done by using namespace std;
We all know
these stuff. So what is the difference between vector and list ? When i
compared the names first time , i can't see any difference, v
ector
is something which has magnitude and direction in maths ( just joking)
and list is our linked list ( doubly or single ). No it is not like
that , Actually
the
vector class only allows to insert in the back side or front side ( No
addition in between ). But list allows. list has function like
insert() , using which we can insert to any position. You may think then why
we need vector? Ofcourse we need because , list costs perfomance
degrade for allowing us to insertion in between the two ends. So If you
don't want to insert in between the front and last end , use vector.
This can be speed up your perfomance.
One other differece is in vector each elements can be accesses using [] . But in list it won't possible.
These are the Key differece. In implementation wise vector is like dynamic array (When i say dynamic array u may think that "Is that same linked list ???"
, Not exactly ,the STL doc says that they have done some perfomance tuning for vector) , and list is the same linke list