Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/cpp-stack.hpp

    r4c80a75 r860f19f  
    1010        node * head;
    1111
    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 ); }
    2014
    2115        void clear() {
    22                 for ( node * nx = head; nx; ) {
    23                         node * cr = nx;
    24                         nx = cr->next;
    25                         delete cr;
     16                for ( node * next = head; next; ) {
     17                        node * crnt = next;
     18                        next = crnt->next;
     19                        delete crnt;
    2620                }
    2721                head = nullptr;
    2822        }
    2923
    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
    3233        ~stack() { clear(); }
    3334
    34         stack & operator=( const stack<T> & o ) {
     35        stack & operator= ( const stack<T> & o ) {
    3536                if ( this == &o ) return *this;
    3637                clear();
     
    3940        }
    4041
    41         bool empty() const {
    42                 return head == nullptr;
    43         }
     42        bool empty() const { return head == nullptr; }
    4443
    45         void push( const T & value ) {
    46                 head = new node{ value, head };  /***/
    47         }
     44        void push( const T & value ) { head = new node{ value, head };  /***/ }
    4845
    4946        T pop() {
Note: See TracChangeset for help on using the changeset viewer.