2020-03-23 10:30:27 +00:00
|
|
|
#ifndef LDS_H
|
|
|
|
#define LDS_H
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-03-27 14:59:28 +00:00
|
|
|
class Node {
|
|
|
|
public:
|
|
|
|
Node() : next(NULL) {};
|
|
|
|
Node(char val) : data(val), next(NULL) {};
|
|
|
|
char data;
|
|
|
|
Node *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Linked list
|
|
|
|
|
|
|
|
class LinkedList {
|
|
|
|
|
|
|
|
public:
|
|
|
|
LinkedList() : head(NULL), tail(NULL) {};
|
|
|
|
void Append(char val);
|
|
|
|
void Push(char val);
|
|
|
|
void Remove(char val);
|
|
|
|
void Replace(char remove, char replace);
|
|
|
|
void Display() const;
|
|
|
|
bool isEmpty() const;
|
|
|
|
Node* Find(char val) const;
|
|
|
|
private:
|
|
|
|
Node *head, *tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Array based stack
|
|
|
|
|
2020-03-23 12:42:02 +00:00
|
|
|
class StackArray {
|
2020-03-23 10:30:27 +00:00
|
|
|
public:
|
2020-03-23 12:42:02 +00:00
|
|
|
StackArray() : top(EMPTY) {};
|
|
|
|
void Push(char val);
|
|
|
|
char Pop();
|
|
|
|
char Top() const;
|
2020-03-23 10:30:27 +00:00
|
|
|
void Display() const;
|
2020-03-23 12:42:02 +00:00
|
|
|
bool isEmpty() const;
|
2020-03-23 10:30:27 +00:00
|
|
|
|
|
|
|
private:
|
2020-03-23 12:42:02 +00:00
|
|
|
enum { EMPTY=-1, MAX=10 };
|
2020-03-23 12:46:49 +00:00
|
|
|
Node stack[MAX];
|
2020-03-23 12:42:02 +00:00
|
|
|
int top;
|
2020-03-23 10:30:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|