Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Andrew Bauer
VTK
Commits
36489010
Commit
36489010
authored
Sep 09, 1994
by
Will Schroeder
Browse files
Initial revision
parent
ec31cee6
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/Stack.hh
0 → 100644
View file @
36489010
/*=========================================================================
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
src/Stack.cc
0 → 100644
View file @
36489010
/*=========================================================================
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
"
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment