Welcome to Mike95.com
Home
WELCOME
ABOUT MIKE95.COM
CONTACT ME


Features
FUNNY JOKES
HUMAN FACTOR


C++
Library Source Code:
CGIPARSE
JSTRING
JVECTOR
JSTACK
JHASHTABLE


COM / ASP
MIKE95 COM SVR
- ASP STACK
- ASP QUEUE
- ASP VECTOR


Tutorials:
TEMPLATES
ALGORITHMS
DESIGN PATTERNS


Sample Work
Internet Based
TASK/BUG TRACKER


Visual C++ / MFC
FLIGHT PATH (C++)
MP3 PLAY LIST


Java
JAVA TALK
BAR GRAPH
WEB CAM


Personal
CONTACT ME
RESUME
PICTURES
TRIPS
JStack
#include "JStack.h"

template <class Etype>
JStack<Etype>::JStack()
{
    m_pTOS = NULL;
}

template <class Etype>
JStack<Etype>::~JStack()
{
    empty();
}

template <class Etype>
const Etype &
JStack<Etype>::peek() const
{
    if ( m_pTOS == NULL )
        throw "JStack is Empty";

    return m_pTOS->value;
}

template <class Etype>
Etype
JStack<Etype>::pop()
{
    if ( m_pTOS == NULL )
        throw "JStack is Empty";

    node* old = m_pTOS;
    m_pTOS = m_pTOS->next;

    const Etype temp = old->value;
    delete old;

    return temp;
}

template <class Etype>
void
JStack<Etype>::empty()
{
    while ( m_pTOS != NULL )
    {
        node* old = m_pTOS;
        m_pTOS = m_pTOS->next;
        delete old;
    }
}

template <class Etype>
void
JStack<Etype>::push( const Etype &item )
{
    m_pTOS = new node( item, m_pTOS );
}

template <class Etype>
int
JStack<Etype>::search( const Etype &item ) const
{
    const node* pJStack = m_pTOS;
    for( int count = 1; pJStack != NULL; count++ )
    {
        if ( pJStack->value == item )
            return count;
        pJStack = pJStack->next;
    }

    return -1;
}


(c)2024 Mike95.com / Site Disclaimer
Site Meter