-
Notifications
You must be signed in to change notification settings - Fork 690
/
C CODE.txt
68 lines (59 loc) · 1003 Bytes
/
C CODE.txt
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
62
63
64
65
66
67
68
// C++ program to reverse a string using stack
#include<bits/stdc++.h>
using namespace std;
//Class to implement Stack
class Stack
{
private:
char * a;
public:
int t;
void pop();
void push(char b);
bool empty();
Stack(int size)
{
a= new char[size];
t=-1;
}
};
// Class to print out element
void Stack::pop()
{
if(empty())
{
cout<<"Empty Stack"<<endl;
return;
}
cout<<a[t];
t--;
}
//Class to insert element
void Stack::push(char b)
{
a[++t]=b;
}
//To check if stack is empty or not
bool Stack::empty()
{
return t<0;
}
//Function to reverse string
void reverse(Stack k)
{
while(!k.empty())
{
k.pop();
}
}
// Driver code
int main() {
Stack block(5);
block.push('h');
block.push('e');
block.push('l');
block.push('l');
block.push('o');
reverse(block);
return 0;
}