-
Notifications
You must be signed in to change notification settings - Fork 0
/
fizzy.cpp
44 lines (34 loc) · 982 Bytes
/
fizzy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "fizzy.h"
#include <cassert>
using std::forward_list;
//Vous pouvez ajouter des fonctions annexes si nécessaire
void fizzy(std::forward_list<int>& dest,
std::forward_list<int>& fwrd,
int comp);
void fizzBuzz(std::forward_list<int>& L,
std::forward_list<int>& F,
std::forward_list<int>& B,
std::forward_list<int>& FB)
{
assert(F.empty() and B.empty() and FB.empty());
// à compléter
fizzy(FB, L, 15);
fizzy(B, L, 5);
fizzy(F, L, 3);
}
void fizzy(std::forward_list<int>& dest,
std::forward_list<int>& fwrd,
int comp) {
auto write_pointer = dest.before_begin();
auto predecessor = fwrd.before_begin();
auto current = next(predecessor);
while (current != fwrd.end()) {
if ((*(current) % comp) == 0) {
dest.splice_after(write_pointer, fwrd, predecessor);
write_pointer = next(write_pointer);
} else {
predecessor = current;
}
current = next(predecessor);
}
}