इस लेख में हम C++ में forward_list::push_front() और forward_list::pop_front() फंक्शन्स के कार्य, सिंटैक्स और उदाहरणों पर चर्चा करेंगे।
forward_list::push_front() क्या है?
forward_list::push_front() C++ STL में एक इनबिल्ट फंक्शन है जो हेडर फाइल में घोषित है। push_front() का उपयोग फॉरवर्ड_लिस्ट के सामने (शुरुआत में) एक एलिमेंट या मान डालने/पुश करने के लिए किया जाता है। जब हम इस फंक्शन का उपयोग करते हैं, तो कंटेनर में पहले से मौजूद पहला एलिमेंट दूसरा बन जाता है, और पुश किया गया एलिमेंट फॉरवर्ड_लिस्ट कंटेनर का पहला एलिमेंट बन जाता है और कंटेनर का आकार 1 से बढ़ जाता है।
सिंटैक्स
flist_container1.push_front(const value_type& value);
रिटर्न मान
यह फंक्शन कुछ भी वापस नहीं करता।
उदाहरण: push_front()
#include <forward_list>
#include <iostream>
using namespace std;
int main() {
forward_list<int> forwardList = {12, 21, 22, 24};
forwardList.push_front(78); // सामने 78 डालें
cout << "Forward List contains: ";
for (auto i = forwardList.begin(); i != forwardList.end(); ++i)
cout << ' ' << *i;
forwardList.sort(); // सॉर्ट करें
cout << "\nForward List after performing sort operation: ";
for (auto i = forwardList.begin(); i != forwardList.end(); ++i)
cout << ' ' << *i;
}
आउटपुट
Forward List contains: 78 12 21 22 24 Forward List after performing sort operation: 12 21 22 24 78
forward_list::pop_front() क्या है?
forward_list::pop_front() C++ STL में एक इनबिल्ट फंक्शन है जो <forward_list> हेडर फाइल में घोषित है। pop_front() का उपयोग फॉरवर्ड_लिस्ट की शुरुआत में मौजूद एलिमेंट को पॉप/हटाने के लिए किया जाता है। जब हम इस फंक्शन का उपयोग करते हैं, तो कंटेनर में पहले से मौजूद पहला एलिमेंट हटा दिया जाता है और पहले एलिमेंट के बगल वाला एलिमेंट फॉरवर्ड_लिस्ट कंटेनर का नया पहला एलिमेंट बन जाता है, और कंटेनर का आकार 1 से कम हो जाता है।
सिंटैक्स
flist_container1.pop_front();
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न मान
यह फंक्शन कुछ भी वापस नहीं करता।
उदाहरण: pop_front()
#include <forward_list>
#include <iostream>
using namespace std;
int main() {
forward_list<int> forwardList = {10, 20, 30};
cout << "list before applying pop operation: ";
for (auto i = forwardList.begin(); i != forwardList.end(); ++i)
cout << ' ' << *i;
forwardList.pop_front(); // पहला एलिमेंट हटाएँ
cout << "\nlist after applying pop operation: ";
for (auto j = forwardList.begin(); j != forwardList.end(); ++j)
cout << ' ' << *j;
}
आउटपुट
list before applying pop operation: 10 20 30 list after applying pop operation: 20 30