- File:
-
- 1 edited
-
doc/papers/general/evaluation/cpp-stack.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/papers/general/evaluation/cpp-stack.hpp
r860f19f r4c80a75 10 10 node * head; 11 11 12 stack() : head( nullptr ) {} 13 stack( const stack<T> & o ) { copy( o ); } 12 void copy( const stack<T> & o ) { 13 node ** cr = &head; 14 for ( node * nx = o.head; nx; nx = nx->next ) { 15 *cr = new node{ nx->value }; /***/ 16 cr = &(*cr)->next; 17 } 18 *cr = nullptr; 19 } 14 20 15 21 void clear() { 16 for ( node * n ext = head; next; ) {17 node * cr nt = next;18 n ext = crnt->next;19 delete cr nt;22 for ( node * nx = head; nx; ) { 23 node * cr = nx; 24 nx = cr->next; 25 delete cr; 20 26 } 21 27 head = nullptr; 22 28 } 23 29 24 void copy( const stack<T> & o ) { 25 node ** crnt = &head; 26 for ( node * next = o.head; next; next = next->next ) { 27 *crnt = new node{ next->value }; /***/ 28 crnt = &(*crnt)->next; 29 } 30 *crnt = nullptr; 31 } 32 30 stack() : head( nullptr ) {} 31 stack( const stack<T> & o ) { copy( o ); } 33 32 ~stack() { clear(); } 34 33 35 stack & operator= ( const stack<T> & o ) {34 stack & operator=( const stack<T> & o ) { 36 35 if ( this == &o ) return *this; 37 36 clear(); … … 40 39 } 41 40 42 bool empty() const { return head == nullptr; } 41 bool empty() const { 42 return head == nullptr; 43 } 43 44 44 void push( const T & value ) { head = new node{ value, head }; /***/ } 45 void push( const T & value ) { 46 head = new node{ value, head }; /***/ 47 } 45 48 46 49 T pop() {
Note:
See TracChangeset
for help on using the changeset viewer.