File: queue2.cpp

package info (click to toggle)
libstxxl 1.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,256 kB
  • ctags: 6,830
  • sloc: cpp: 39,594; ansic: 4,217; perl: 566; sh: 555; xml: 174; makefile: 21
file content (51 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (5)
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
45
46
47
48
49
50
51
/***************************************************************************
 *  examples/containers/queue2.cpp
 *
 *  Part of the STXXL. See http://stxxl.sourceforge.net
 *
 *  Copyright (C) 2013 Daniel Feist <daniel.feist@student.kit.edu>
 *
 *  Distributed under the Boost Software License, Version 1.0.
 *  (See accompanying file LICENSE_1_0.txt or copy at
 *  http://www.boost.org/LICENSE_1_0.txt)
 **************************************************************************/

#include <stxxl/queue>
#include <iostream>

int main()
{
    // template parameter <value_type, block_size, allocation_strategy, size_type>
    typedef stxxl::queue<unsigned int> a_queue;

    // construct queue with default parameters
    a_queue my_queue;

    unsigned int random;
    stxxl::random_number32 rand32;  // define random number generator
    stxxl::uint64 number_of_elements = 64 * 1024 * 1024;

    // push random values in the queue
    for (stxxl::uint64 i = 0; i < number_of_elements; i++)
    {
        random = rand32();  // generate random integers from interval [0,2^32)
        my_queue.push(random);
    }

    unsigned int last_inserted = my_queue.back();
    STXXL_MSG("last element inserted: " << last_inserted);

    // identify smaller element than first_inserted, search in growth-direction (front->back)
    while (!my_queue.empty())
    {
        if (last_inserted > my_queue.front())
        {
            STXXL_MSG("found smaller element: " << my_queue.front() << " than last inserted element");
            break;
        }
        std::cout << my_queue.front() << " " << std::endl;
        my_queue.pop();
    }

    return 0;
}