hello there. there's an error in my program that I cannot identify. Every time i call a function for my declared variable of type Stack, there will suddenly be a run time error. I really don't get what's wrong with my code because my implementation seems to be right but still I get this error. I hope someone could help me. Here are parts of my code:
class declaration:
Code:
class Stack{
private:
node *head, *top;
public:
Stack();
void push(char[]);
bool pop();
char* peek();
bool isEmpty();
void display();
};
Stack::Stack(){
head=top=NULL;
}
bool Stack::isEmpty(){
if(top==NULL)
return true;
return false;
}
void Stack::push(char x[]){
node *n = new node(x);
/* if(n==NULL)
return false;*/
if(isEmpty())
top = n;
else{
top->next = n;
n->prev = top;
top = n;
}
// return true;
}
bool Stack::pop(){
if(isEmpty())
return false;
node *del = top;
top = top->prev;
if(top!=NULL)
top->next = NULL;
del->prev = NULL;
return true;
}
char* Stack::peek(){
return top->item;
}
I get an error whenever I perform something like this:
Code:
void main(){
Stack s;
s.push(word); //run-time error
s.peek(); //run-time error
}
please take a look at my class declaration/implementation, the error might be found there. I'm really bad at looking for errors, I swear.