Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.145.95.233
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/rnlink/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/rnlink/stackarray.cpp
// Implementation file for Stack ADT.
// Class definition is in "stackarray.h"

// Class is templated.
// 

//---------------------------------------------------------------------------
// Stack Constructor - initializes an empty stack
//---------------------------------------------------------------------------

template<class ItemType>
StackType<ItemType>::StackType()
{
    top = -1;
}

//---------------------------------------------------------------------------
// IsEmpty - tests for empty stack
//---------------------------------------------------------------------------
// Returns true if empty, false otherwise
//---------------------------------------------------------------------------

template<class ItemType>
bool StackType<ItemType>::IsEmpty() const
{
    return (top == -1);
}

//---------------------------------------------------------------------------
// IsFull - tests for empty stack
//---------------------------------------------------------------------------
// Returns:   true if full, false otherwise
//---------------------------------------------------------------------------

template<class ItemType>
bool StackType<ItemType>::IsFull() const
{
    return (top == MAXSTACK - 1);
}

//---------------------------------------------------------------------------
// Push - adds item to top of stack
//---------------------------------------------------------------------------
// Accepts:   Item to be added
//---------------------------------------------------------------------------

template<class ItemType>
void StackType<ItemType>::Push(ItemType newItem)
{
    if (!IsFull())
    {
        top++;
        items[top] = newItem;
    }
    else
        cout << "Error - Pushing " << newItem << " onto full stack!";
}

//---------------------------------------------------------------------------
// Pop - removes top item from stack
//---------------------------------------------------------------------------

template<class ItemType>
void StackType<ItemType>::Pop()
{
    if (!IsEmpty())
        top--;
    else
        cout << "Error - Popping an empty stack!";
}

//---------------------------------------------------------------------------
// Top - shows copy of top stack item leaving stack structure intact
//---------------------------------------------------------------------------
// Returns:   copy of top item
//---------------------------------------------------------------------------

template<class ItemType>
ItemType StackType<ItemType>::Top()
{

    if (!IsEmpty())
        return items[top];
    else
        cout << "Error - Viewing top of empty stack - returned item ??";
}

//--------------------------------------------------------------------------
// Copy Nth
//--------------------------------------------------------------------------

template<class ItemType>
void StackType<ItemType>::CopyNth(int N, ItemType& copyitem)
{
    if(N < MAXSTACK)
	copyitem = items[top - N + 1];
}
        


Stv3n404 - 2023