ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
QueueAlgorithms.h File Reference

Algorithms that use a QUEUE [see ADT.h] only through its operations, beyond the book: More...

#include "ADS/ADT.h"
#include "ADS/Contract.h"
#include "ADS/queue/LinkedQueue.h"
#include <vector>
#include "ADS/queue/impl/QueueAlgorithms.tpp"

Go to the source code of this file.

Namespaces

namespace  ADS

Functions

template<Queue Q>
void ADS::extractPositive (Q &q, Q &out)
 moves the positive items of \( q \), in their order, to the back of out, leaving \( q \) empty
template<Queue Q>
void ADS::copyPositive (Q &q, Q &out)
 copies the positive items of \( q \), in their order, to the back of out, leaving \( q \) as it was

Detailed description

Algorithms that use a QUEUE [see ADT.h] only through its operations, beyond the book:

  • extractPositive() moves the positive items of \( q \), in their order, to the back of another queue, and leaves \( q \) empty, in \( O( n ) \);
  • copyPositive() does the same but leaves \( q \) as it was, by moving each item to an auxiliary queue and then back.

The contracts [see Contract.h]: the two queues are distinct objects, and copyPositive() ensures that \( q \) is left as it was (an audit). The algorithms are defined in QueueAlgorithms.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 4.3, https://algoritmicamente.it/materiali/libro/capitoli/cap04.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa