. . . : .
#include "stdafx.h"
#include <list>
#include <iostream>
using namespace std;
struct Point
{
Point(int x, int y): X(x), Y(y)
{
}
Point(): X(0), Y(0)
{
}
int X;
int Y;
};
void DemonstrateList()
{
// 1. - .
list<Point> points;
// 2.
// 2.1
points.push_back(Point(13, 22));
points.push_back(Point(22, 13));
// 2.2 ( )
int array[4] = { 2, 6, 4, 8 };
points.insert(points.begin(),
array,
array + 4);
// 2.3 ( )
list<Point> otherContainer;
otherContainer.push_back(Point(2, 3));
points.insert(points.begin(),
otherContainer.begin(),
otherContainer.end());
// 3. :
// advance, ,
// , .
auto element13Iterator = points.begin();
advance(element13Iterator, 12);
cout << element13Iterator->X;
// 4.
// 4.1
for (auto iterator = points.begin(); iterator!= points.end(); ++iterator)
{
cout << "Point " << "X = " << iterator->X << ", Y = " << iterator->Y;
}
// 4.2 , for.
for (auto &element: points)
{
cout << "Point " << "X = " << element.X << ", Y = " << element.Y;
}
// 5.
auto whereToInsert = points.begin();
advance(whereToInsert, 1);
points.insert(
whereToInsert,
Point(666, 666));
// 6. .
auto whereToDelete = points.begin();
advance(whereToDelete, 1);
points.erase(whereToDelete);
// 7.
auto pointIterator = points.begin();
while (pointIterator!= points.end())
{
if (pointIterator->X > 13) // .
{
pointIterator = points.erase(pointIterator);
}
else
{
++pointIterator;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
DemonstrateList();
}
Forward_list
. . .
(deque)
. .
-
. .