-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.h
More file actions
36 lines (30 loc) · 1 KB
/
Copy pathStack.h
File metadata and controls
36 lines (30 loc) · 1 KB
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
#ifndef STACK_H
#define STACK_H
#include "Node.h"
// 1. Linked List-Based Stack
class StackLL {
private:
Node* top; // Private data member for encapsulation
public:
StackLL();
~StackLL(); // Destructor to free all nodes
void push(int data); // Adds item to top
int pop(); // Removes and returns top item
int peek(); // Returns top item without removing
bool isEmpty(); // Returns true if stack is empty
};
// 2. Array-Based Stack
class StackArray {
private:
int* arr; // Dynamic array
int topIndex; // Tracks the current top of the stack
int capacity; // Max size of the stack
public:
StackArray(int size);
~StackArray(); // Destructor to free the array
void push(int data); // Handles Stack Overflow
int pop(); // Handles Stack Underflow
int peek(); // Returns top item
bool isEmpty(); // Returns true if empty
};
#endif