“Daftar CPP” Kode Jawaban

Daftar CPP

#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";
}
Witty Wombat

Contoh daftar std CPP

#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";
}
Clever Cowfish

Daftar di c

#include <bits/stdc++.h>
using namespace std;
void display(list<int> &lst){
    list<int> :: iterator it;
    for(it = lst.begin(); it != lst.end(); it++){
         cout<<*it<<" ";
    }
}
int main(){
    list<int> list1;
    int data, size;
    cout<<"Enter the list Size ";
    cin>>size;
    for(int i = 0; i<size; i++){
        cout<<"Enter the element of the list ";
        cin>>data;
        list1.push_back(data);
    }
    cout<<endl;
    display(list1);
  return 0;
}

Akash

Jawaban yang mirip dengan “Daftar CPP”

Pertanyaan yang mirip dengan “Daftar CPP”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya