Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test-comb.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <iostream>
29
30# include <ah-comb.H>
31
32using namespace std;
33
34
35void test()
36{
37 DynList<char> l1 = { 'a', 'b', 'c' };
38 DynList<char> l2 = { 'A', 'B', 'C' };
39 DynList<char> l3 = { '1', '2', '3' };
40 DynList<char> l4 = { '5', '6', '7'};
41
42 DynList<DynList<char>> l = { l1, l2, l3, l4 };
43
44 traverse_perm(l, [] (auto s)
45 {
46 cout << "s = "; s.for_each([] (auto c) { cout << c << " "; });
47 cout << endl;
48 return true;
49 });
50
51 cout << endl
52 << endl;
53
54 transpose(l).for_each([] (const auto & row)
55 {
56 row.for_each([] (auto i) { cout << i << " "; });
57 cout << endl;
58 });
59
60 auto aux = l;
62 aux.for_each([] (const auto & row)
63 {
64 row.for_each([] (auto i) { cout << i << " "; });
65 cout << endl;
66 });
67}
68
69
70int main()
71{
72 test();
73 return 0;
74}
Combinatorics utilities: permutations, combinations and matrix transposition.
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:779
bool traverse_perm(const DynList< DynList< T > > &l, Op &op)
Traverse all the possible permutations that can be done of a list of lists and on each permutation pe...
Definition ah-comb.H:465
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
DynList< DynList< T > > transpose(const DynList< DynList< T > > &l)
Transpose a matrix represented as a list of lists.
Definition ah-comb.H:250
void in_place_transpose(C< C< T > > &l)
In-place transpose of a rectangular matrix stored as a nested container.
Definition ah-comb.H:301
STL namespace.
void test()
Definition test-comb.C:35
int main()
Definition test-comb.C:70
DynList< char > l3
DynList< int > l1
DynList< int > l2
DynList< int > l