কম্পিউটার

C++ STL-এ ভেক্টর::begin() এবং ভেক্টর::end()


ভেক্টর::বেগিন() ফাংশন হল একটি দ্বিমুখী পুনরাবৃত্তিকারী যা ধারকটির প্রথম উপাদানের দিকে নির্দেশ করে একটি পুনরাবৃত্তিকারী ফেরত দিতে ব্যবহৃত হয়।

ভেক্টর::এন্ড() ফাংশন হল একটি দ্বিমুখী পুনরাবৃত্তিকারী যা ধারকটির শেষ উপাদানটির দিকে নির্দেশ করে একটি পুনরাবৃত্তিকারী ফেরত দিতে ব্যবহৃত হয়।

অ্যালগরিদম

Begin
   Initialize the vector v.
   Declare the vector v1 and iterator it to the vector.
   Insert the elements of the vector.
   Print the elements.
End.

উদাহরণ কোড

#include<iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
   vector<int> v = { 50,60,70,80,90}, v1; //declaring v(with values), v1 as vector.
   vector<int>::iterator it;
   //declaring an ierator
   it = v.insert(v.begin(), 40);
   //inserting a value in v vector with specified the position at the beginning using the function begin().

   it = v.insert(v.begin(), 1, 30);
   //inserting a value with its size in v vector with specified the position at the beginning using the function begin().

   cout << "The vector1 elements are: ";
   for ( it = v.begin(); it != v.end(); ++it)
      cout << *it << " "<<endl; // printing the values of v vector

      v1.insert(v1.begin(),v.begin(),v.end());
      //inserting all values from beginning to end, by using begin() and end() function, of v
      vector in v1 vector pointing at the beginning using begin() function.
     
      cout << "The vector2 elements are: ";
      for (it = v1.begin(); it != v1.end(); ++it)
         cout << *it << " "<<endl; // printing the values of v1 vector
   return 0;
}
এর মান প্রিন্ট করা

আউটপুট

The vector1 elements are: 
30
40
50
60
70
80
90
The vector2 elements are: 
30
40
50
60
70
80
90

  1. C++ STL-এ Array::fill() এবং array::swap()?

  2. C++ STL-এ ভেক্টর সন্নিবেশ() ফাংশন

  3. সেট::begin() এবং সেট::end() C++ STL এ

  4. STL এ ভেক্টর বাস্তবায়নের জন্য C++ প্রোগ্রাম