I'm trying to write a stack implementation that makes use of a single link list.

The new Stack implementation can inherit from stackADT which I previously used with an array opposed to the link list I want to make use of now.

Here is the stackADT

#include "StackADT.h"

StackADT::StackADT() : current(-1) {}

void StackADT::push(void *el){
  if (!isFull()) {
    incrCurrent();
    insert(el);
  }
}

void* StackADT::pop(){
  void *el = 0;
  if (!isEmpty()) {
    el = remove();
    decrCurrent();
  }
  return el;
}

bool StackADT::isEmpty() {
  return (current < 0) ? true : false;
}

bool StackADT::isFull() {
  return false; 
}

StackADT::~StackADT() {
}


int StackADT::getCurrent() {
  return current; 
}

void StackADT::incrCurrent() { 
  current++; 
}

void StackADT::decrCurrent() {
  current--; 
}
#ifndef STACKADT_H
#define STACKADT_H

  // Stack Abstract Data Type
  class StackADT {
    public:
      StackADT();
      void push(void*);  // Template method
      void* pop();       // Template method 
      bool isEmpty();    // Is not implementation dependent.  Abstract class controls the variable
      virtual bool isFull();
      virtual ~StackADT();
    protected:
      virtual void insert(void *) = 0; // Called by push in insert the next element in the stack
      virtual void* remove() = 0;      //  Called by pop to return the next element in the stack
      int getCurrent();    // Returns the number of elements
    private:
      void incrCurrent();  // Used by push and pop
      void decrCurrent();  // Used by push and pop
      int current;         // Number of elements in the stack
  };

#endif

Any help would be appreciated.
Thanks

Member Avatar for jencas

What is your problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.