A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/cpp/list-cbegin-and-cend-function-in-c-stl/ below:

list cbegin() and cend() function in C++ STL

list cbegin() and cend() function in C++ STL

Last Updated : 13 Jun, 2022

list_name.cbegin()

Parameters: The function does not accept any parameters.
Return value: It returns a constant random access iterator which points to the beginning of the list.
Below programs illustrate the above function: 

CPP
// C++ program to illustrate the
// cbegin() function
#include <bits/stdc++.h>
using namespace std;

int main()
{
    // declaration of list
    list<int> lis = { 5, 6, 7, 8, 9 };

    // Prints the first element
    cout << "The first element is: " << *lis.cbegin();

    // printing list elements
    cout << "\nList: ";

    for (auto it = lis.cbegin(); it != lis.end(); ++it)
        cout << *it << " ";

    return 0;
}

Output: 
The first element is: 5
List: 5 6 7 8 9

 

Time Complexity: O(1)

Auxiliary Space: O(1)

list_name.cend()


Parameters: The function does not accepts any parameter.
Return value: It returns a constant random access iterator which points to the end of the list.
Below program illustrates the function:

CPP
// C++ program to illustrate the
// cend() function
#include <bits/stdc++.h>
using namespace std;

int main()
{

    // declaration of list
    list<int> lis = { 10, 20, 30, 40, 50 };

    // printing list elements
    cout << "List: " << endl;

    for (auto it = lis.cbegin(); it != lis.cend(); ++it)
        cout << *it << " ";

    return 0;
}

Output: 
List: 
10 20 30 40 50

 

Time Complexity: O(1)

Auxiliary Space: O(1)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4