ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
StockTrading.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File StockTrading.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
46/*--------------------------------------------------------------------------*/
47/*----------------------------- DEFINITIONS --------------------------------*/
48/*--------------------------------------------------------------------------*/
49
50#ifndef __ADS_StockTrading
51 #define __ADS_StockTrading
52/* self-identification: #endif constant */
53
54/*--------------------------------------------------------------------------*/
55/*------------------------------ INCLUDES ----------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58#include "ADS/Contract.h"
59
60#include <algorithm>
61#include <cstddef>
62#include <optional>
63#include <vector>
64
65/*--------------------------------------------------------------------------*/
66/*--------------------------- NAMESPACE ------------------------------------*/
67/*--------------------------------------------------------------------------*/
68
69namespace ADS
70{
71
94template< class T >
95T maxProfit( const std::vector< T > & prices , std::size_t k );
96
111template< class T >
112std::optional< T > maxProfitExactly( const std::vector< T > & prices ,
113 std::size_t k );
114
115/*--------------------------------------------------------------------------*/
116
117} // end( namespace ADS )
118
119/*--------------------------------------------------------------------------*/
120/*-------------------------- IMPLEMENTATION --------------------------------*/
121/*--------------------------------------------------------------------------*/
122
123#include "ADS/optimization/impl/StockTrading.tpp"
124
125/*--------------------------------------------------------------------------*/
126
127#endif /* StockTrading.h included */
128
129/*--------------------------------------------------------------------------*/
130/*------------------------ End File StockTrading.h -------------------------*/
131/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
T maxProfit(const std::vector< T > &prices, std::size_t k)
the largest gain of at most transactions on the prices
std::optional< T > maxProfitExactly(const std::vector< T > &prices, std::size_t k)
the largest gain of exactly transactions on the prices, nothing if there are fewer than days
Definition ADT.h:96