forked from super30admin/PreCourse-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_2.cpp
More file actions
49 lines (42 loc) · 915 Bytes
/
Copy pathExercise_2.cpp
File metadata and controls
49 lines (42 loc) · 915 Bytes
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
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// A structure to represent a stack
// Time Complexity : isEmpty = O(1), push = O(1) , pop = O(1),peek =O(1)
// Space Complexity : O(1)
class StackNode {
public:
int data;
StackNode* newNode(int data)
int isEmpty(StackNode* root)
{
//Your code here
if (root == nullptr) return 1;
else return 0;
}
void push(StackNode** root, int data)
{
//Your code here
StackNode *temp=newNode(data);
temp->next=(*root);
(*root)=temp;
}
int pop(StackNode** root)
{
//Your code here
if (*root == nullptr)
{
return -1;
}
StackNode *tempRoot= *root;
*root=tempRoot->next;
int retTemp=tempRoot->data;
delete tempRoot;
return retTemp;
}
int peek(StackNode* root)
{
//Your code here
return root->data;
}
}