//-*-c++-*- #ifndef SIMPLE_STACK_CC #define SIMPLE_STACK_CC // Copyright (c) 1994,1995 Ohio Board of Regents and the University of // Cincinnati. All Rights Reserved. // // Author: Dale Martin (dmartin@thor.ece.uc.edu) // Name: SimpleStack.cc // Description: Function bodies for the simple stack // // $Id: SimpleStack.cc,v 1.1.1.1 2007/03/15 15:45:06 rmadhoun Exp $ // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public // License along with this library; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //--------------------------------------------------------------------------- static const char* simple_stack_cc_rcsid = "$Id: SimpleStack.cc,v 1.1.1.1 2007/03/15 15:45:06 rmadhoun Exp $"; #include template < class Element > SimpleStack< Element >::SimpleStack() { handle = NULL; } template < class Element > SimpleStack< Element >::~SimpleStack() { // walk down the list and destroy all of the containers while (handle!=NULL){ Container * last = handle; handle = handle->next; delete last; } } template < class Element > Element SimpleStack< Element >::pop() { if (handle==NULL){ return NULL; } else { register Container < Element > * temp = handle; register Element returnData = temp->data; handle=temp->next; delete temp; return returnData; } } template < class Element > void SimpleStack< Element >::push(Element newElement) { if (handle==NULL){ register Container < Element > * temp; temp = new Container < Element >; temp->next = NULL; temp->data = newElement; handle = temp; } else { register Container < Element > * temp; temp = new Container < Element >; temp->data = newElement; temp->next = handle; handle = temp; } } #endif