Solstice::Stack - A basic stack object.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Stack - A basic stack object.

SYNOPSIS

Top

  use Solstice::Stack;

  my $stack = new Solstice::Stack;

  # Push an element onto the stack
  $stack->push($element);

  # Remove the last element in the stack, and return it
  $element = $stack->pop();

  # Return the last element in the stack
  $element = $stack->top();

  # Clear the stack
  $stack->clear();

  my $iterator = $list->iterator();
  while ($iterator->hasNext()) {
    my $element = $iterator->next();
  }

DESCRIPTION

Top

Provides a set of functionality for creating and manipulating a stack.

Export

No symbols exported.

Methods

new ()

Creates and returns an empty Solstice::Stack object.

clear()

Removes all entries from the Stack object.

push($element)

Adds an element to the end of the Stack.

pop()

Remove the last element in the Stack and return it.

top()

Returns the last element in the Stack, without removing it.

isEmpty()

Returns a boolean describing whether the internal Stack array is empty.

_init()

Initialize the Stack by clearing it.

Modules Used

Carp (Carp).

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 2065 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::Stack;

# $Id: List.pm 2065 2005-03-05 01:16:48Z tleffler $

use 5.006_000;
use strict;
use warnings;
use Carp qw(confess);

use constant TRUE  => 1;
use constant FALSE => 0;

our ($VERSION) = ('$Revision: 2065 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my ($obj) = @_;
    
    my $self = bless {}, $obj;
    $self->Solstice::Stack::_init(@_);

    return $self;
}

sub clear {
    my ($self) = @_;
    @{$self->{'_stack'}} = ();
    return TRUE;
}

sub push {
    my ($self, $element) = @_;
    CORE::push(@{$self->{'_stack'}}, $element);
}

sub pop {
    my ($self) = @_;
    return CORE::pop(@{$self->{'_stack'}});
}

sub top {
    my ($self) = @_;
    return $self->{'_stack'}->[-1];
}

sub isEmpty {
    my ($self) = @_;
    return scalar(@{$self->{'_stack'}}) ? FALSE : TRUE;
}

sub _init {
    my ($self) = @_;
    
    $self->Solstice::Stack::clear();
    
    return TRUE;
}


1;

__END__