-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.h
61 lines (46 loc) · 1.48 KB
/
Stack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Name:Sameeraa Kandalgaonkar
NetID: SXK220350
This is the header file for the Stack class.
It contains the outline for the Stack class
*/
#ifndef STACK_H
#define STACK_H
#include <iostream>
#include <string>
#include "Node.h"
class Stack
{
// o Attribute names
private:
// ▪ Head - node pointer
Node *head;
public:
// o Default constructor
Stack() {head = nullptr;}
// o Overloaded constructor
// ▪ Node pointer parameter
// ▪ Head points at new node
Stack(Node *n) : head(n) {}
// o Copy constructor
// ▪ Stack parameter
// ▪ Create a copy of the stack passed in (enforces data hiding and data integrity)
// ▪ Assign head to first node
Stack(const Stack &s);
// o Destructor
// ▪ Recursively delete linked list (-5 points if not recursive)
~Stack();
void deleteList(Node* curr);
// o Accessor and mutator for head
Node *getHead() {return head;}
void setHead(Node *h1) {head = h1;}
// ▪ Overloaded << operator for output
friend std::ostream &operator<<(std::ostream&, const Stack&);
// ▪ Overloaded >> operator
Stack& operator>>(Node *&node);
// ▪ Overloaded << operator
Stack& operator<<(Node *node);
//function to check if stack is empty
bool isEmpty() const;
};
#endif