The C++ programming language benefits from having built-in implementations of Data Structures and Algorithms within its Standard Template Library (STL). In cases where these are not available, developers are required to manually write the entire code, resulting in increased compilation time for the compiler and a more time-intensive process for the programmer working at the computer.
The array is a crucial Data Structure that acts as a collection to store various data types such as integers, characters, strings, long integers, and short integers. By using the pushfront method, we can insert elements into the List Data Structure, while the pushback function lets us append data at the rear of the List Data Structure.
Syntax
listname.push_front(value)
C++ code
// Here we are writing down the C++ programming language code to demonstrate
// the concept of list::push_front() and list::push_back() in C++ STL
#include <iostream>
#include <list>
using namespace std;
// The main driver code functionality starts from here
int main()
{
// the below code snippet helps us with creating a List Data structure
// in C++ programming language STL (Standard Template Library)
list<int> mylist{ 1, 2, 3, 4, 5 };
//the below code snippet helps us with pushing the data to the list
mylist.push_front(6);
// Now list becomes 6, 1, 2, 3, 4, 5
// Now the list contains the elements 6, 1, 2, 3, 4, 5
// now we are using the auto function available for us in the C++
// programming language Standard Template Library helping us to print data
for (auto it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
// end of the C++ programming language code
}
Output:
/ t m p / d J J Y Z f g 6J u.o
// Output of the List created
6 1 2 3 4 5
C++ code
// Here we are writing down the C++ programming language code to demonstrate
// the concept of list::push_front() and list::push_back() in C++ STL
#include <iostream>
#include <list>
using namespace std;
// The main driver code functionality starts from here
int main()
{
// the below code snippet helps us with creating a List Data structure
// in C++ programming language STL (Standard Template Library)
list<int> mylist{};
//the below code snippet helps us push the data to the list
mylist.push_front(43);
mylist.push_front(58);
mylist.push_front(24);
mylist.push_front(6);
mylist.push_front(45);
mylist.push_front(89);
mylist.push_front(7);
// Now list becomes 6 7 24 43 45 58 89
// Now, we shall implement the sorting function
mylist.sort();
// now we are using the auto function available for us in the C++
// programming language Standard Template Library helping us to print
//data
for (auto it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
// end of the C++ programming language code
}
Output:
/ t m p / d J J Y Z f g 6J u.o
6 7 24 43 45 58 89
C++ code
// Here we are writing down the C++ programming language code to demonstrate
// the concept of list::push_front() and list::push_back() in C++ STL
#include <iostream>
#include <list>
using namespace std;
// The main driver code functionality starts from here
int main()
{
// the below code snippet helps us with creating a List Data structure
// in C++ programming language STL (Standard Template Library)
list<int> mylist{ 1, 2, 3, 4, 5 };
//The code snippet below helps us push the data to the list
mylist.push_back(6);
// Now the list becomes 1, 2, 3, 4, 5, 6
// now we are using the auto function available for us in the C++
// programming language Standard Template Library helping us to print
//data
for (auto it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
// end of the C++ programming language code
}
Output:
/ t m p / d J J Y Z f g 6J u.o
1 2 3 4 5 6
C++ code
// Here we are writing down the C++ programming language code to demonstrate
// the concept of list::push_front() and list::push_back() in C++ STL
#include <iostream>
#include <list>
using namespace std;
// The main driver code functionality starts from here
int main()
{
// the below code snippet helps us with creating a List Data structure
// in C++ programming language STL (Standard Template Library)
list<int> mylist{};
//The code snippet below helps us push the data to the list
mylist.push_back(7);
mylist.push_back(89);
mylist.push_back(45);
mylist.push_back(6);
mylist.push_back(24);
mylist.push_back(58);
mylist.push_back(43);
// Now the list becomes 6 7 24 43 45 58 89
// Now, we shall implement the sorting function
mylist.sort();
// now we are using the auto function available for us in the C++
// programming language Standard Template Library helping us to print
//data
for (auto it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
// end of the C++ programming language code
}
Output:
6 7 24 43 45 58 89