PROBLEM WITH AN ARRAY BASED STACK.

Hi everyone, I've been trying to write a stack updating member function for a class called stackType. The stack is array based and the function takes a parameter of type int and checks if the parameter is part of a stack, -If the parameter is contained in the stack the function must move it to the top of the stack, -If the parameter is not in the stack than the top item of the stack is removed and the parameter takes its place. My data members are:
1
2
3
int maxStackSize;
int stackTop;
int* list;


I am new to dealing with stacks and I've tried writing this function for hours without success. so please, if anyone has any idea how to code this function, you can just give me the pseudo code, just so that I get an idea.
From a data structures point of view you really should only have the ability to query the top of the stack, anything below it shouldn't be "checkable".

Did you come up with this requirement or did you get it off a book/school assignment?
Last edited on
its a school assignment on a data structures course.
Topic archived. No new replies allowed.