Last active
August 29, 2015 14:22
-
-
Save kazmura11/a6acce63296165c2c801 to your computer and use it in GitHub Desktop.
How to use std::list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <list> | |
#include <algorithm> | |
#include <iterator> | |
int main() | |
{ | |
std::list<int> ls { 12, 2, 3, 1, 5, 4, 13, 7, 8, 9, 10, 11, 6}; | |
// とりあえず出力 | |
std::copy(ls.begin(), ls.end(), std::ostream_iterator<int>(std::cout, " ")); | |
std::cout << "\n"; | |
// 4を探す | |
auto iter = std::find(ls.begin(), ls.end(), 4); | |
int index = static_cast<int>(std::distance(ls.begin(), iter)); | |
// 4がでるまで引きます | |
for (int i = 0; i < index; i++) | |
{ | |
ls.pop_front(); | |
} | |
std::copy(ls.begin(), ls.end(), std::ostream_iterator<int>(std::cout, " ")); | |
std::cout << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment