Is there anything you notice that is incorrect about this?
Code:
#include<iostream>
#include<stack>
using namespace std;
class Lstack {
private:
char Link *top; /*Pointer to first element*/
int size; /*Count number of elements*/
public:
Lstack(int sz =DefaultListSize) {top = NULL; size = 0;}
~Lstack() {clear();} /*Destructor*/
void clear() {
while (top != NULL) { /*Delete link nodes*/
Link* temp = top;
top = top->next;
delete temp;
}
size = 0;
}
bool push(const Elem& item) {
top = new Link(item, top);
size++;
return true;
}
bool pop(Elem& item) {
if(size == 0) return false;
it = top->element;
Link *ltemp = top->next;
delete top;
top = ltemp;
size--;
return true;
}
bool topValue(Elem& it) const {
if (size ==0) return false;
it = top->element;
return true;
}
int length() const {return size;}
bool isEmpty() const {
if (top == NULL) return true;
else return false;
};
int main(){
return 0;
}