TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
 Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

 Author Feedback Print Article Comment on this Article

Making Linked Lists More User-Friendly-2 : Page 2

 by Danny Kalev, C++ Pro
 Oct 1, 2001
 Page 2 of 3

WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

Step 1: Creating a List Object
The header <list> contains the declaration of std::list and its specialized algorithms. Our first step is to create an empty list of integers called li:
``````#include <list>
using std::list;
int main()
{
list <int> li;
}``````

To insert a single element, use the push_back() member function:

```

This widget requires JavaScript to run. Visit Site for more...

```
li.push_back(1);``````

To remove the last element of a list, use the pop_back() member function

``````
li.pop_back();``````

The push_front() member function inserts an element before the list's beginning:

``````
li.push_front(0); // the first element is now 0, not 1``````

Similarly, pop_front() removes the first element of a list:

``````
li.pop_front();``````

To remove a certain value from the list, use remove(). remove(n) removes all the elements that equal to n from the list:

``````
li.remove(0); // li doesn't contain any zeros anymore``````

 Author Feedback Email Article Print Article Comment on this Article
Comment and Contribute

(Maximum characters: 1200). You have 1200 characters left.

Thanks for your registration, follow us on our social networks to keep up-to-date