okay here is my stack code, unfortunetly it uses a list class but hopefully you should be able to figure it out without seeing the list code:
Stack header:
Code:
#pragma once
#include "list.h"
typedef ListItemType StackItemType;
class Stack
{
public:
Stack(void);
~Stack(void);
void Push(StackItemType item);
StackItemType Pop(void);
StackItemType Peek(void);
inline bool IsEmpty() const { return m_container.IsEmpty();}
inline bool IsFull() const { return m_container.IsFull();}
inline int GetLength() const { return m_container.GetLength();}
private:
int m_top;
List m_container;
};
Stack Source Code:
Code:
#include "StdAfx.h"
#include ".\stack.h"
Stack::Stack(void)
{
m_top = 0;
}
Stack::~Stack(void)
{
}
void Stack::Push(StackItemType item)
{
m_top++;
m_container.Insert(m_top, (ListItemType) item );
}
StackItemType Stack::Pop(void)
{
StackItemType s;
if (IsEmpty()) return NULL;
m_container.Retrieve(m_top, (ListItemType *) &s );
m_container.Remove(m_top);
m_top--;
return s;
}
StackItemType Stack::Peek(void)
{
StackItemType s;
if (IsEmpty()) return NULL;
m_container.Retrieve( m_top, (ListItemType *) &s );
return s;
}
If you could solve my question thatd really help me out thanks