Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testArrayQueue.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# include <tpl_arrayQueue.H>
30
31# define NumItems 10
32
33using namespace std;
34
35int main()
36{
38 unsigned i;
39
40 for (i = 0; i < NumItems; i++)
41 {
42 q.putn(1);
43 q.rear() = i;
44 printf("%u ", i);
45 }
46
47 cout << endl
48 << "queue = ";
49 q.for_each([] (unsigned i) { cout << " " << i; });
50 cout << endl;
51
52 cout << "rear de 0: " << q.rear() << endl
53 << "rear de 1: " << q.rear(1) << endl
54 << "rear de 2: " << q.rear(2)<< endl
55 << "rear de 3: " << q.rear(3)<< endl
56 << "la cola deberia ser: " << endl;
57 while (not q.is_empty())
58 cout << q.get() << " ";
59
60 cout << endl;
61}
Very simple queue implemented with a contiguous array.
constexpr bool is_empty() const noexcept
Return true if the queue is empty.
T get() noexcept
Remove the oldest item of the queue.
T & putn(const size_t n) noexcept
Put n cells to the queue in constant time.
T & rear(const size_t i=0) const noexcept
Return the i-th youngest item.
void for_each(Operation &operation)
Traverse all the container and performs an operation on each element.
Definition ah-dry.H:779
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.
STL namespace.
#define NumItems
int main()
Circular queue implementations backed by arrays.