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