Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
B.Eckel - Thinking in C++, Vol.2, 2nd edition.pdf
Скачиваний:
59
Добавлен:
08.05.2013
Размер:
2.09 Mб
Скачать

will contain abs(n-m) copies of that value, where abs( ) is the absolute value. The return value is the end of the output range

Example

It’s easiest to see the set operations demonstrated using simple vectors of characters, so you view the sets more easily. These characters are randomly generated and then sorted, but the duplicates are not removed so you can see what the set operations do when duplicates are involved.

//: C05:SetOperations.cpp

// Set operations on sorted ranges #include <vector>

#include <algorithm> #include "PrintSequence.h" #include "Generators.h" using namespace std;

int main() {

vector<char> v(50), v2(50); CharGen g;

generate(v.begin(), v.end(), g); generate(v2.begin(), v2.end(), g); sort(v.begin(), v.end()); sort(v2.begin(), v2.end()); print(v, "v", "");

print(v2, "v2", "");

bool b = includes(v.begin(), v.end(), v.begin() + v.size()/2, v.end());

cout << "includes: " <<

(b ? "true" : "false") << endl; vector<char> v3, v4, v5, v6; set_union(v.begin(), v.end(),

v2.begin(), v2.end(), back_inserter(v3)); print(v3, "set_union", ""); set_intersection(v.begin(), v.end(),

v2.begin(), v2.end(), back_inserter(v4)); print(v4, "set_intersection", ""); set_difference(v.begin(), v.end(),

v2.begin(), v2.end(), back_inserter(v5)); print(v5, "set_difference", ""); set_symmetric_difference(v.begin(), v.end(),

v2.begin(), v2.end(), back_inserter(v6)); print(v6, "set_symmetric_difference","");

Chapter 15: Multiple Inheritance

321

Соседние файлы в предмете Численные методы
  • #
    08.05.20133.99 Mб25A.Menezes, P.van Oorschot,S.Vanstone - HANDBOOK OF APPLIED CRYPTOGRAPHY.djvu
  • #
  • #
    08.05.20135.91 Mб28B.Eckel - Thinking in Java, 3rd edition (beta).pdf
  • #
  • #
    08.05.20136.09 Mб20D.MacKay - Information Theory, Inference, and Learning Algorithms.djvu
  • #
    08.05.20133.85 Mб19DIGITAL Visual Fortran ver.5.0 - Programmers Guide to Fortran.djvu
  • #
    08.05.20131.84 Mб16E.A.Lee, P.Varaiya - Structure and Interpretation of Signals and Systems.djvu