Libreria C ++ Forward_list - Funzione merge ()

Descrizione

La funzione C ++ std::forward_list::merge()unisce due forward_lists ordinate in una usando la semantica di spostamento. Le forward_lists dovrebbero essere ordinate in ordine crescente.

Dichiarazione

Di seguito è riportata la dichiarazione per la funzione std :: forward_list :: merge () nel modulo std :: forward_list header.

C ++ 11

void merge (forward_list&& x);

Parametri

x - Un altro oggetto forward_list dello stesso tipo.

Valore di ritorno

Nessuna

Eccezioni

Questa funzione membro non genera mai eccezioni.

Complessità temporale

Lineare cioè O (n)

Esempio

L'esempio seguente mostra l'utilizzo della funzione std :: forward_list :: merge ().

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

   forward_list<int> fl1 = {1, 5, 11, 31};
   forward_list<int> fl2 = {10, 20, 30};

   fl1.merge(move(fl2));

   cout << "List contains following elements" << endl;

   for (auto it = fl1.begin(); it != fl1.end(); ++it)
      cout << *it << endl;

   return 0;
}

Compiliamo ed eseguiamo il programma sopra, questo produrrà il seguente risultato:

List contains following elements
1
5
10
11
20
30
31