Answers for "list library"

C++
1

cpp std list example

#include <algorithm>
#include <iostream>
#include <list>
 
int main()
{
    // Create a list containing integers
    std::list<int> l = { 7, 5, 16, 8 };
 
    // Add an integer to the front of the list
    l.push_front(25);
    // Add an integer to the back of the list
    l.push_back(13);
 
    // Insert an integer before 16 by searching
    auto it = std::find(l.begin(), l.end(), 16);
    if (it != l.end()) {
        l.insert(it, 42);
    }
 
    // Print out the list
    std::cout << "l = { ";
    for (int n : l) {
        std::cout << n << ", ";
    }
    std::cout << "};n";
}
Posted by: Guest on January-11-2021
0

list python

#creating the list
whatever_list = ["apple", "orange", "pear"]

#adding things to lists:
whatever_list.append("banana") #adds banana on to the list

#printing something from the list.
#remember, lists start from zero!
print(whatever_list[0]) #This prints apple
print(whatever_list[1]) #This prints orange and so on.

#removing something from a list
whatever_list.remove("orange")

#these are the basic list functions.
Posted by: Guest on March-20-2021

Browse Popular Code Answers by Language