Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions StackRev1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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;
}