ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | 
            Last change
 on this file since bd12159 was             4c80a75, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago           | 
        
        
          | 
             
update evaluation programs 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            947 bytes
           | 
        
      
      
| Line |   | 
|---|
| 1 | #include "cpp-vstack.hpp"
 | 
|---|
| 2 | #include <utility>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | stack::node::node( const object & v, node * n ) : value( v.new_copy() ), next( n ) {}
 | 
|---|
| 5 | 
 | 
|---|
| 6 | void stack::copy( const stack & o ) {
 | 
|---|
| 7 |         node ** cr = &head;
 | 
|---|
| 8 |         for ( node * nx = o.head; nx; nx = nx->next ) {
 | 
|---|
| 9 |                 *cr = new node{ *nx->value }; /***/
 | 
|---|
| 10 |                 cr = &(*cr)->next;
 | 
|---|
| 11 |         }
 | 
|---|
| 12 |         *cr = nullptr;
 | 
|---|
| 13 | }
 | 
|---|
| 14 | 
 | 
|---|
| 15 | void stack::clear() {
 | 
|---|
| 16 |         for ( node * nx = head; nx; ) {
 | 
|---|
| 17 |                 node * cr = nx;
 | 
|---|
| 18 |                 nx = cr->next;
 | 
|---|
| 19 |                 delete cr;
 | 
|---|
| 20 |         }
 | 
|---|
| 21 |         head = nullptr;
 | 
|---|
| 22 | }
 | 
|---|
| 23 | 
 | 
|---|
| 24 | stack::stack() : head( nullptr ) {}
 | 
|---|
| 25 | stack::stack( const stack & o ) { copy( o ); }
 | 
|---|
| 26 | stack::~stack() { clear(); }
 | 
|---|
| 27 | 
 | 
|---|
| 28 | stack & stack::operator=( const stack & o ) {
 | 
|---|
| 29 |         if ( this == &o ) return *this;
 | 
|---|
| 30 |         clear();
 | 
|---|
| 31 |         copy( o );
 | 
|---|
| 32 |         return *this;
 | 
|---|
| 33 | }
 | 
|---|
| 34 | 
 | 
|---|
| 35 | bool stack::empty() const {
 | 
|---|
| 36 |         return head == nullptr;
 | 
|---|
| 37 | }
 | 
|---|
| 38 | 
 | 
|---|
| 39 | void stack::push( const object & value ) {
 | 
|---|
| 40 |         head = new node{ value, head }; /***/
 | 
|---|
| 41 | }
 | 
|---|
| 42 | 
 | 
|---|
| 43 | ptr<object> stack::pop() {
 | 
|---|
| 44 |         node * n = head;
 | 
|---|
| 45 |         head = n->next;
 | 
|---|
| 46 |         ptr<object> v = std::move( n->value );
 | 
|---|
| 47 |         delete n;
 | 
|---|
| 48 |         return v;
 | 
|---|
| 49 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.