Code Search for Developers
 
 
  

Stack.h from Magnus at Krugle


Show Stack.h syntax highlighted

// Copyright (C) 1994 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.

// Contents: Definition and implementation of classes: Stack<T>.
//
// Principal Author: Sergey Lyutikov
//
// Status: Useable.
//
// Revision History:
//
// Special Notes:
//
// * To instantiate StackOf<T>, class T must have an assignment
//   operator, a copy constructor, an == operator, and destructor.
//
// * Alternative implementation of StackOf class, uses ListRep as
//   the DataRep.
//

#ifndef _STACK_H_
#define _STACK_H_

#include "RefCounter.h"
#include "ObjectOf.h"
#include "List.h"
#include "Cell.h"


template < class T > class StackOf : public ObjectOf< ListRep<T> > {

public:

  // Constructors:

  StackOf( ) : ObjectOf< ListRep<T> >( new ListRep<T>() ) { }
  // Default constructor makes empty stack.

  StackOf( const T& t ) : ObjectOf< ListRep<T> >( new ListRep<T>(t) ) { }
  // Cast constructor T -> StackOf<T>

  // copy constructor, operator=, and destructor supplied by compiler.

  void push( const T& t ) { this->change()->insert( t, 0 ); }

  T pop( ) { 
    T res = this->look()->element( 0 ); 
    this->change()->removeElementOfIndex( 0 ); 
    return res;
  }

  void popAll( ) { 
    while ( this->look()->length() ) this->change()->removeElementOfIndex( 0 ); 
  }

  Bool isEmpty( ) const { return !this->look()->length(); }

  Bool isntEmpty( ) const { return this->look()->length(); }

};

#endif  // _STACK_H_




See more files for this project here

Magnus

Magnus is a special purpose mathematical package for Infinite Group Theory computations

Project homepage: http://sourceforge.net/projects/magnus
Programming language(s): C,C++
License: other

  Associations.h
  BTree.h
  BlackBox.h
  Cell.h
  Chars.h
  DArray.h
  DCell.h
  DList.h
  File.h
  GCD.h
  GlobalRandom.h
  IStreamPoll.h
  Int2.h
  List.h
  LogWatcher.h
  MagnusHome.h
  MultiDimArray.h
  QuickAssociations.h
  RandomNumbers.h
  Set.h
  Stack.h
  Timer.h
  Type.h
  Vector.h
  WordParser.h
  conversions.h