I've been trying to fix this code for 2 days now and i still don't understand where the error is coming from.
this is my stackLL.h file
#include<iostream>
using namespace std;
class Node
{
public:
int data;
Node *link;
};
class stackLL
{
public:
stackLL();
~stackLL();
bool isEmpty();
bool isFull();
void push(int value);
void pop();
int returnTop();
private:
Node *top;
};
void stackLL::push(int value)
{
Node *temp= new Node;
temp->data=value;
temp->link=top;
top=temp;
delete temp;
}
void stackLL::pop()
{
Node *temp= new Node;
if(top!= NULL)
{
temp=top;
top=top->link;
delete temp;
}
else
cout << "Cannot remove from an empty stack" << endl;
}
bool stackLL::isEmpty()
{
return(top==0);
}
bool stackLL::isFull()
{
return false;
}
int stackLL::returnTop()
{
return top->data;
}
stackLL::stackLL()
{
top=NULL;
}
stackLL::~stackLL()
{
Node *temp=new Node;
while(top!=NULL)
{
temp=top;
top=top->link;
delete temp;
}
}
this is my stackLL.cpp file
#include<iostream>
#include "stackLL.h"
using namespace std;
int main()
{
stackLL stack;
stack.push(3);
stack.returnTop();
return 0;
}