STL vector and list Difference

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值