MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/queue_ex.cpp:33–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33int main()
34{
35 queue_of_int q;
36
37 // initialize rand()
38 srand(time(0));
39
40 for (int i = 0; i < 20; ++i)
41 {
42 int a = rand()&0xFF;
43
44 // note that adding a to the queue "consumes" the value of a because
45 // all container classes move values around by swapping them rather
46 // than copying them. So a is swapped into the queue which results
47 // in a having an initial value for its type (for int types that value
48 // is just some undefined value. )
49 q.enqueue(a);
50
51 }
52
53
54 cout << "The contents of the queue are:\n";
55 while (q.move_next())
56 cout << q.element() << " ";
57
58 cout << "\n\nNow we sort the queue and its contents are:\n";
59 q.sort(); // note that we don't have to call q.reset() to put the enumerator
60 // back at the start of the queue because calling sort() does
61 // that automatically for us. (In general, modifying a container
62 // will reset the enumerator).
63 while (q.move_next())
64 cout << q.element() << " ";
65
66
67 cout << "\n\nNow we remove the numbers from the queue:\n";
68 while (q.size() > 0)
69 {
70 int a;
71 q.dequeue(a);
72 cout << a << " ";
73 }
74
75
76 cout << endl;
77}
78

Callers

nothing calls this directly

Calls 5

sortMethod · 0.80
randClass · 0.50
enqueueMethod · 0.45
move_nextMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected