This is one of those brain farts i always get.. but i need a peek method in this stack class and am having horrible time figuring out how to do it correctly can someone help me out plz

i think it should look something like

void peek(stack* head)

{

if(head!=NULL)

{

while(head->next!=NULL)

{

cout<<head->element<<"->";

head=head->next;

}

cout<<head->element;

cout<<endl;

}

else

cout<<"the stack is empty\n";

}

but it doesnt work like i think it should...

but below is the code i have so if someone could help it would be much appreciated..

#ifndef STACK_H

#define STACK_H

#include "List.h"

template< typename STACKTYPE >

class Stack : private List< STACKTYPE >

{

public:

void push(const STACKTYPE &data)

{

insertAtFront(data);

}

bool pop( STACKTYPE &data)

{

return removeFromFront(data);

}

bool isStackEmpty() const

{

return List<STACKTYPE>::isEmpty();

}

void printStack() const

{

List<STACKTYPE>::print();

}

};

#endif

// I use this linkedlist to implement my stack

#ifndef LIST_H

#define LIST_H

#include <iostream>

using std::cout;

#include "ListNode.h"

template< typename NODETYPE >

class List

{

public:

List();

~List();

void insertAtFront( const NODETYPE &);

bool removeFromFront( NODETYPE & );

bool isEmpty() const;

void print() const;

private:

ListNode<NODETYPE> *firstPtr;

ListNode<NODETYPE> *lastPtr;

ListNode< NODETYPE > *getNewNode( const NODETYPE &);

};

template< typename NODETYPE >

List< NODETYPE >::List():

firstPtr(0), lastPtr(0) { }

template< typename NODETYPE >

List< NODETYPE >::~List()

{

if(!isEmpty())

{

cout << "Destroying LinkedList ...\n";

ListNode< NODETYPE > *currentPtr = firstPtr;

ListNode< NODETYPE > *tempPtr;

while(currentPtr != 0)

{

tempPtr = currentPtr;

cout << tempPtr->data << '\n';

currentPtr = currentPtr->nextPtr;

delete tempPtr;

}

}

cout << "All nodes destroyed\n\n";

}

template< typename NODETYPE >

void List< NODETYPE >::insertAtFront( const NODETYPE &value)

{

ListNode< NODETYPE > *newPtr = getNewNode( value );

if( isEmpty())

firstPtr = lastPtr = newPtr;

else{

newPtr->nextPtr = firstPtr;

firstPtr = newPtr;

}

}

template <typename NODETYPE >

bool List< NODETYPE >::removeFromFront( NODETYPE &value )

{

if( isEmpty() )

return false;

else{

ListNode< NODETYPE > *tempPtr = firstPtr;

if(firstPtr == lastPtr)

firstPtr = lastPtr = 0;

else

firstPtr = firstPtr->nextPtr;

value = tempPtr->data;

delete tempPtr;

return true;

}

}

template< typename NODETYPE>

bool List< NODETYPE >::isEmpty() const

{

return firstPtr == 0;

}

template< typename NODETYPE >

ListNode< NODETYPE > *List< NODETYPE >::getNewNode( const NODETYPE &value)

{

return new ListNode< NODETYPE >(value);

}

template< typename NODETYPE>

void List< NODETYPE>::print() const

{

if( isEmpty())

{

cout << "The list is empty\n\n";

return;

}

ListNode< NODETYPE> *currentPtr = firstPtr;

cout<<"The List is: ";

while(currentPtr != 0)

{

cout << currentPtr->data << ' ';

currentPtr = currentPtr->nextPtr;

}

cout << "\n\n";

}

#endif

//ListNode Class

#ifndef LISTNODE_H

#define LISTNODE_H

template< typename NODETYPE > class List;

template < typename NODETYPE>

class ListNode

{

friend class List< NODETYPE >;

public:

ListNode( const NODETYPE & );

NODETYPE getData() const;

private:

NODETYPE data;

ListNode< NODETYPE > *nextPtr;

};

template< typename NODETYPE>

ListNode< NODETYPE >::ListNode( const NODETYPE &info )

: data( info ), nextPtr( 0 )

{

}

template< typename NODETYPE >

NODETYPE ListNode< NODETYPE >::getData() const

{

return data;

}

#endif