// 30_30-7.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <deque>

using namespace std;

void disp(deque<int> &obj)
{
	for (int i = 0; i < (int)obj.size(); i++) {
		cout << obj[i] << " ";
	}
	cout << '\n';
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i;
	deque<int> d1, d2;
	deque<int>::iterator p, p1, p2;
	deque<int>::reverse_iterator rp;

	cout << "-----(1)値を設定\n";
	for (i = 0; i < 10; i++) {
		d1.push_back(i+100);
	}
	cout << "d1の長さ=" << d1.size() << '\n';

	cout << "-----(2)添字処理でd1内容を表示\n";
	for (i = 0; i < (int)d1.size(); i++) {
		cout << d1[i] << " ";
	}
	cout << '\n';

	cout << "-----(3)反復子処理でd1内容を表示\n";
	for (p = d1.begin(); p != d1.end(); p++) {
		cout << *p << " ";
	}
	cout << '\n';

	cout << "-----(4)逆進反復子処理でd1内容を後ろから表示\n";
	for (rp = d1.rbegin(); rp != d1.rend(); rp++) {
		cout << *rp << " ";
	}
	cout << '\n';

	cout << "-----(5)d1の先頭と末尾の要素を表示\n";
	cout << "front=" << d1.front() << '\n';
	cout << "back=" << d1.back() << '\n';

	cout << "-----(6)d2にassign関数で10個のデータ(初期値88)を設定\n";
	d2.assign(10, 88);
	disp(d2);

	cout << "-----(7)d2にassign関数でd1[2]から3個のデータを設定\n";
	p = d1.begin() + 2;
	d2.assign(p, p+3);
	disp(d2);

	cout << "-----(8)d2にd1を丸コピーし内容表示\n";
	d2 = d1;
	disp(d2);

	cout << "-----(9)d1とd2を比較\n";
	if (d1 == d2) {
		cout << "d1 == d2である\n";
	}
	else {
		cout << "d1 != d2である\n";
	}

	cout << "-----(10)添字処理と反復子処理とat関数でd2内容を変更\n";
	p = d2.begin() + 2;
	*p = 222;
	d2[3] = 333;
	d2.at(4) = 444;
	disp(d2);

	cout << "-----(11)再びd1とd2を比較\n";
	if (d1 == d2) {
		cout << "d1 == d2である\n";
	}
	else {
		cout << "d1 != d2である\n";
	}
	
	cout << "-----(12)d2の3番目に9999を挿入(insert)\n";
	p = d2.begin() + 3;
	d2.insert(p, 9999);
	disp(d2);

	cout << "-----(13)d2の3番目の要素を削除(erase)\n";
	p = d2.begin() + 3;
	d2.erase(p);
	disp(d2);

	cout << "-----(14)d2の2番目から3個を削除(erase)\n";
	p1 = d2.begin() + 2;
	d2.erase(p1, p1+3);
	disp(d2);

	cout << "-----(15)d2をクリア(clear)\n";
	d2.clear();
	cout << "d2の長さ=" << d1.size() << '\n';

	cout << "-----(16)d2をempty(空)判定する\n";
	if (d2.empty()) {
		cout << "d2は空\n";
	}
	else {
		cout << "d2は空ではない\n";
	}

	cout << "-----(17)d2に0〜9を格納\n";
	for (i = 0; i < 10; i++) {
		d2.push_back(i);
	}
	disp(d2);

	cout << "-----(18)d2の5番目に、d1の区間[2,4)の内容を挿入\n";
	p = d2.begin() + 5;
	p1 = d1.begin() + 2;
	p2 = d1.begin() + 4;
	d2.insert(p, p1, p2);
	disp(d2);

	cout << "-----(19)d2の最後の要素を削除\n";
	d2.pop_back();
	disp(d2);

	cout << "-----(20)d2の先頭に要素を追加\n";
	d2.push_front(123);
	disp(d2);

	cout << "-----(21)d2の先頭要素を削除\n";
	d2.pop_front();
	disp(d2);

	cout << "-----(22)d2のサイズを8にする\n";
	d2.resize(8);
	disp(d2);

	cout << "-----(23)d2のサイズを12にし、拡張部に-1を入れる\n";
	d2.resize(12, -1);
	disp(d2);

	cout << "-----(24)現在のd1とd2の内容\n";
	cout << "d1: ";
	disp(d1);
	cout << "d2: ";
	disp(d2);

	cout << "-----(25)d1とd2を交換(swap)する\n";
	d1.swap(d2);
	cout << "d1: ";
	disp(d1);
	cout << "d2: ";
	disp(d2);

	cout << "-----(26)待ち行列モデル(行列にデータ追加)\n";
	d1.clear();
	for (i = 0; i < 5; i++) {
		d1.push_back(i+500);
	}
	disp(d1);

	cout << "-----(27)待ち行列モデル(行列から先出しする)\n";
	while (!d1.empty()) {
		cout << d1.front();
		d1.pop_front();
		cout << "(size=" << d1.size() << ")";
	}
	cout << '\n';
	

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

