An update will be applied December 9th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit 36489010 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent ec31cee6
/*=========================================================================
Program: Visualization Library
Module: Stack.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlStack - create and manipulate lists of objects
// .SECTION Description
// vlStack is a general object for creating and manipulating lists
// of objects. vlStack also serves as a base class for lists of
// specific types of objects.
#ifndef __vlStack_hh
#define __vlStack_hh
#include "Object.hh"
class vlStackElement
{
public:
vlObject *Item;
vlStackElement *Next;
};
class vlStack : public vlObject
{
public:
vlStack();
~vlStack();
void PrintSelf(ostream& os, vlIndent indent);
char *GetClassName() {return "vlStack";};
void Push(vlObject *);
vlObject *Pop();
vlObject *GetTop();
int GetNumberOfItems();
protected:
int NumberOfItems;
vlStackElement *Top;
vlStackElement *Bottom;
};
#endif
/*=========================================================================
Program: Visualization Library
Module: Stack.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "Stack.hh"
// Description:
// Construct with empty stack.
vlStack::vlStack()
{
this->NumberOfItems = 0;
this->Top = NULL;
this->Bottom = NULL;
}
vlStack::~vlStack()
{
vlStackElement *p;
for ( p=this->Top; p != NULL; p = p->Next )
{
delete p;
}
}
// Description:
// Add an object to the top of the stack. Does not prevent duplicate entries.
void vlStack::Push(vlObject *a)
{
vlStackElement *elem;
elem = new vlStackElement;
if ( this->Top == NULL )
this->Bottom = elem;
else
elem->Next = this->Top;
this->Top = elem;
elem->Item = a;
this->NumberOfItems++;
}
// Description:
// Remove an object from the top of the list.
vlObject *vlStack::Pop()
{
int i;
vlObject *item;
vlStackElement *next;
if ( this->Top == NULL ) return NULL;
item = this->Top->Item;
next = this->Top->Next;
delete this->Top;
if ( this->Top == this->Bottom )
this->Top = this->Bottom = NULL;
else
this->Top = next;
this->NumberOfItems--;
return item;
}
// Description:
// Return the number of objects in the stack.
vlObject *vlStack::GetTop()
{
if ( this->Top != NULL )
return this->Top->Item;
else
return NULL;
}
// Description:
// Return the number of objects in the stack.
int vlStack::GetNumberOfItems()
{
return this->NumberOfItems;
}
void vlStack::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlStack::GetClassName()))
{
vlObject::PrintSelf(os,indent);
os << indent << "Number Of Items: " << this->NumberOfItems << "\n";
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment