|
ADS
Algorithms and Data Structures
|
Algorithms that use a STACK [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 "ADS/sequence/List.h"#include "ADS/stack/ArrayStack.h"#include "ADS/stack/SequenceStack.h"#include <algorithm>#include <span>#include <string>#include <string_view>#include <vector>#include "ADS/stack/impl/StackAlgorithms.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| bool | ADS::isPalindrome (const std::string &s) |
| whether \( s \) reads the same from both ends | |
| template<Stack S> | |
| void | ADS::sortStack (S &s) |
| sorts \( s \) with the least item on top | |
| template<Stack S> | |
| void | ADS::removeGreater (S &s, const typename S::Item &k) |
| removes the items larger than \( k \), the others in their order | |
| template<Stack S, class F> | |
| void | ADS::forEachBottomUp (S &s, F &&f) |
| f( x ) on each item \( x \), from the bottom to the top | |
| bool | ADS::isDyckWord (std::span< const int > w) |
| whether the sequence \( w \) of \( +1 \) and \( -1 \) is a Dyck word, i.e., has no negative prefix sum | |
| bool | ADS::isMatched (std::string_view s) |
| whether \( s \), a string of the brackets (), [] and {}, is matched, in \( O( n ) \) | |
| template<Stack S, Queue Q = LinkedQueue< typename S::Item >> | |
| void | ADS::reverseWithQueue (S &s) |
| the order of the items of \( s \) reversed by a QUEUE, the only operations of \( s \) being push() and pop() | |
Algorithms that use a STACK [see ADT.h] only through its operations, beyond the book:
The contracts [see Contract.h]: sortStack() ensures a sorted stack with the same number of items, removeGreater() a stack with no item larger than \( k \), forEachBottomUp() the stack as it was, and reverseWithQueue() the items in the reverse order; all are audits, checked by popping the stack and pushing it back. The algorithms are defined in StackAlgorithms.tpp.