To create an empty list in C++, you can use the std::list
class for a doubly linked list.
In this example,
header for the std::list
class.std::list()
and assign it to the variable emptyList
.#include <iostream>
#include <list>
int main() {
std::list<int> emptyList;
std::cout << "Empty list size: " << emptyList.size() << std::endl;
return 0;
}
Empty list size: 0
In this example,
header for the std::list
class.std::list()
and assign it to the variable emptyList
.#include <iostream>
#include <list>
#include <string>
int main() {
std::list<std::string> emptyList;
std::cout << "Empty list size: " << emptyList.size() << std::endl;
return 0;
}
Empty list size: 0
In this tutorial, we learned How to create an Empty List in C++ language with well detailed examples.