14 Nisan 2020 Salı

STL Set Algoritmaları

Giriş
STL algoritmalarını işlevlerine göre gruplamak anlamayı çok daha kolaylaştırıyor. Bu algoritmalar için şu satır kullanılır.
#include <algorithm>

includes
Açıklaması şöyle. İkinci dizinin birinci dizinin alt kümesi olup olmadığını döndürür.
includes can be used to find out whether a set is a superset(returns a boolean). To check if it is subset, just switch the 2 sets.
Şöyle yaparız.
std::vector<int> a({1});
std::vector<int> b({1,1,1});

// Outputs 'false'
std::cout << std::boolalpha
  << std::includes(a.begin(), a.end(), b.begin(), b.end()) << '\n';
set_difference metodu
std::set_difference metodu yazısına taşıdım.

set_intersection metodu
std::set_intersection metodu yazısına taşıdım.

set_symmetric_difference metodu
Açıklaması şöyle. İki setin kesişmeyen elemanlarını verir.
set_symmetric_difference computes the elements in either set but not both.
İki tane setin symmetric_difference() sonucu şöyledir.
[1,2,3],[2,3,4] -> [1,4]
set_union metodu
std::set_union metodu yazısına taşıdım

Hiç yorum yok:

Yorum Gönder