Mercurial > Algorithms__Sedgewick
diff algs4-c++/src/Buffer.hpp @ 22:c2cbfdf528f6
1.3.44 Ugh. I would never use this in real life but it seems to be what they want.
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Tue, 23 Jun 2015 11:02:31 -0500 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/algs4-c++/src/Buffer.hpp Tue Jun 23 11:02:31 2015 -0500 1.3 @@ -0,0 +1,34 @@ 1.4 +// Sedgewick and Wayne, Algorithms, 4th ed. problem 1.3.44 1.5 + 1.6 +// Two stack implementation. I don't know why anyone would actually want to use 1.7 +// an implmentation like this, but it's what they suggested in the problem. I 1.8 +// guess it's just an "exercise" after all. 1.9 + 1.10 + 1.11 +#ifndef BUFFER_HPP 1.12 +#define BUFFER_HPP 1.13 + 1.14 +#include <cstddef> 1.15 + 1.16 +#include "Stack.hpp" 1.17 + 1.18 +class Buffer { 1.19 +public: 1.20 + Buffer( void ); 1.21 + 1.22 + void insert( char c ); 1.23 + char get( void ); 1.24 + char delete( void ); 1.25 + void left( size_t k ); 1.26 + void right( size_t k ); 1.27 + size_t size( void ); 1.28 + 1.29 +private: 1.30 + size_t cursor; 1.31 + 1.32 + bool use_s1; 1.33 + Stack<char> s1; 1.34 + Stack<char> s2; 1.35 + }; 1.36 + 1.37 +#endif