⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liststability.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C20:ListStability.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Things don't move around in lists

#include "Noisy.h"

#include <list>

#include <iostream>

#include <algorithm>

using namespace std;



int main() {

  list<Noisy> l;

  ostream_iterator<Noisy> out(cout, " ");

  generate_n(back_inserter(l), 25, NoisyGen());

  cout << "\n Printing the list:" << endl;

  copy(l.begin(), l.end(), out);

  cout << "\n Reversing the list:" << endl;

  l.reverse();

  copy(l.begin(), l.end(), out);

  cout << "\n Sorting the list:" << endl;

  l.sort();

  copy(l.begin(), l.end(), out);

  cout << "\n Swapping two elements:" << endl;

  list<Noisy>::iterator it1, it2;

  it1 = it2 = l.begin();

  it2++;

  swap(*it1, *it2);

  cout << endl;

  copy(l.begin(), l.end(), out);

  cout << "\n Using generic reverse(): " << endl;

  reverse(l.begin(), l.end());

  cout << endl;

  copy(l.begin(), l.end(), out);

  cout << "\n Cleanup" << endl;

} ///:~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -