EI'm doing a project on data structure class, which have to implement different types of structures.
Such as arrays, linked, doubly linked, circular etc ...
Each of these structures uses a type, either stack, queue, or list.
Example:
VectorStructure.h
template<typename T>
class VectorStructure{
public:
int addOnPosition(T element, int pos);
int addOnBeginning(T element);
int add(T element);
int addElementOrdered(T element);
T removeFromPos(int pos);
T removeFromBeginning();
T remove();
T removeElement(T element);
}
Each implementation of those types contains code exactly like the others.
Stack: is a LIFO structure, only uses methods: add(T element) and remove();
Queue: is a FIFO structure, only uses methods: add(T element) and removeFromBeginning();
List: is a dynamic array, can uses any of those methods and some extras.
My idea is: Implement all those functions on a base class, and make those types use only the needed methods of the base. I thought i could use inheritance, but then a stack could access an unallowed function from base class since its it "child" Also thought i could use abstract class, but, in order to compile i should implement all methods contained on the abstract class.
The types (they're only examples, there are some other methods that are the same on all types):
List.h
template<typename T>
class List{
public:
int addOnPosition(T element, int pos);
int addOnBeginning(T element);
int add(T element);
int addElementOrdered(T element);
T removeFromPos(int pos);
T removeFromBeginning();
T remove();
T removeElement(T element);
Stack.h
template<typename T>
class Stack{
public:
int add(T element);
T remove();
Queue.h
template<typename T>
class Queue{
public:
int add(T element);
T removeFromBeginning();
Is there is any way to implement this idea?