Vector In C++ STL | C++ Tutorials for Beginners #71

preview_player
Показать описание
C++ Vectors Tutorial: Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators.

Best Hindi Videos For Learning Programming:

►C Language Complete Course In Hindi -

►JavaScript Complete Course In Hindi -

►Django Complete Course In Hindi -

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

Video like zaroor kar dena 😊
Will try to keep the course short as well as complete!
Ek sentence me please batao if you are getting the concepts?

CodeWithHarry
Автор

member function- Resize
To resize the vector into any length.
Let us assume we have m size vector and want n size vector , now two cases are arisen-
1.if n<m
then we will take upto n number elements in vector and remaining elements will be erased.
2.else n>m
then all the m elements will remain same and now extra n-m elements will be added those can be default or initialised by user.
This the form what we use in c++ code.
vec1.resize(n)

RachanaDatta
Автор

*max_element(vec.begin(), vec. end())
Return the max element in the vector

*min_element (vec.begin(), vec. end())
Return the min element of the vector

kaustubhraut
Автор

vector_name.front(): it gives us the vector front element.
vector_name.back(): It gives us the vector last element.

harpreetbansal
Автор

Sir, if possible make Playlist on competitive programming

ruchi
Автор

swap() : exchanges the elements in the two vectors
vector<int> v1={1, 2, 3, 4};
vector<int> v2={9, 8, 7, 6};
v1.swap(v2); //the elements inside the vector will be swapped.

irfanmohammad
Автор

resize() function is very useful you can resize your vector without using realloc() function and pointers.
Example : vec. resize(4);
vec.resize (3);

heeru
Автор

vector::emplace_back is nice, it doesn't create copies of your objects unlike push_back.
Example: vector.push_back(HeavyObject(1, 2, 3)) will create first a temporary object we passed into the function, then a copy of that object will be created (by calling copy constructor) in the actual vector, and then the temporary will be destructed.
Compared to vector.emplace_back(1, 2, 3) which just takes constructor arguments, and directly creates the object inside the vector. No need for creation and destruction of temporary objects.
I read it's often ~8% faster by making such trivial changes.

VivekYadav-dsoz
Автор

we can use auto instead of typing vector<T>::iterator variable = vector.begin()

auto iter = vector.begin()

one more thing for in loop

for(auto it: myvec){
cout<< *it<<;
} as it is an iterator we need to dereference it to get the value at the location it is pointing.
vector.end is a useful method that tells the end of the vector

raghavgupta
Автор

I watch ad on your channel without clicking the skip option because you really work hard on your contents and make our lives easier. Thankyou Harry

anikatabassum
Автор

congratulations to all who have reached here

prensudangol
Автор

Dude! you just saved my lab finals. I was looking for a convenient playlist. And I found you. Literally, easy way to process and understand things also time-saving. I'm from BD, thanks, man!

studytimewithjency
Автор

Function resize() in vectors is used to resize the memory sized allocation after previous allocation/s.

ayanavadas
Автор

Superb explanation of STL sir. Really like the effort you are putting for creating such a good content. Please make advance STL in one video(if possible). And sir, please give source code of STL videos. It was given for all videos at your website but not given for STL.

brijeshpeshvani
Автор

When I searched about topic and find your video about it, can't tell you my happiness of saving time and was assured to fully understand it, Thank you master harry.

samisaleem
Автор

Erase function -
We can erase a single or all elements of the vector
If we want erase single element- vector_name.erase(element number)
If we want erase all vector or range of vector-
Vector_name.erase(a, b);

vijaysaharan
Автор

front : it gives element at front of vector
back : it gives last element from vector

aryan_
Автор

clear() - delete all the elements of the vector.
you are doing great harry bhai.

programmerdai
Автор

sir, .emplace() function is used to add a certain element to a certain position in a vector
it takes two arguments one the position where we want to insert the item and second the value which we want to insert at that point

shatviksmit
Автор

if the user want to fill the values from the end, user can use rbegin.
for ex.
below is the syntax to declare a reverse iterator (rit) pointing at the end of the vector(for him, it's a reverse beginning). 'rbegin' is a public member function.
vector<int>::reverse_iterator rit = vec1.rbegin();
after this you can always initiate a for loop to fill the values.
for(;rit!=vec1.rend();++rit){
cout<<"enter the element"<<endl;
cin>>*rit;
}
in above loop rend is a reverse end(which means it will point it at the beginning)

vaibhavrane