From accee4f30ae88bc1ee45420d356f6e937a5206b4 Mon Sep 17 00:00:00 2001 From: NicWebster96 Date: Wed, 30 Sep 2020 16:19:04 -0700 Subject: [PATCH] pop_back.md --- list/pop_back.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 list/pop_back.md diff --git a/list/pop_back.md b/list/pop_back.md new file mode 100644 index 00000000..239edccf --- /dev/null +++ b/list/pop_back.md @@ -0,0 +1,40 @@ +# pop_back + +**Description** : The list::pop_back() function in C++ STL removes the last element in the list container. + +**Example**: + +```cpp +// Demonstrates pop_back() +#include +#include + +int main(){ + //declare an empty list + std::list mylist; + + //append elements to the list + mylist.push_back(1); + mylist.push_back(2); + mylist.push_back(3); + + //print list elements + std::cout << "List elements before pop_back()" << std::endl; + for (auto element : mylist) { + std::cout << element << " "; + } + std::cout << std::endl; + + //pop element from the back + mylist.pop_back(); + + //print list elements + std::cout << "List elements after pop_back()" << std::endl; + for (auto element : mylist) { + std::cout << element << " "; + } + + return 0; +} +``` +**[Run Code](https://rextester.com/IBH29509)**