Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse a string using stack. #576

Open
rathoresrikant opened this issue Oct 27, 2018 · 3 comments
Open

Reverse a string using stack. #576

rathoresrikant opened this issue Oct 27, 2018 · 3 comments

Comments

@rathoresrikant
Copy link
Owner

Programming language : Any
Directory : Data Structures/Stacks

@shreenaathia
Copy link

Can I work on this issue ?

@vivekarya99
Copy link

def createStack():
stack=[]
return stack

Function to determine the size of the stack

def size(stack):
return len(stack)

Stack is empty if the size is 0

def isEmpty(stack):
if size(stack) == 0:
return true

Function to add an item to stack .

It increases size by 1

def push(stack,item):
stack.append(item)

#Function to remove an item from stack.

It decreases size by 1

def pop(stack):
if isEmpty(stack): return
return stack.pop()

A stack based function to reverse a string

def reverse(string):
n = len(string)

# Create a empty stack 
stack = createStack() 

# Push all characters of string to stack 
for i in range(0,n,1): 
    push(stack,string[i]) 

# Making the string empty since all  
#characters are saved in stack  
string="" 

# Pop all characters of string and  
# put them back to string 
for i in range(0,n,1): 
    string+=pop(stack) 
      
return string 

Driver program to test above functions

string="GeeksQuiz"
string = reverse(string)
print("Reversed string is " + string)

rathoresrikant pushed a commit that referenced this issue Oct 29, 2018
#576 Added String reverse in c++ using stl stack
mhdshameel added a commit to mhdshameel/HacktoberFestContribute that referenced this issue Oct 29, 2018
This is regarding the issue rathoresrikant#576 
Used a simple linked list based stack implementation.
@adityasinghbaghel
Copy link

adityasinghbaghel commented Oct 23, 2019

Reversing string using stack.

stack.txt
Most of the stack problem is easy to solve using stack of characters.
#576

Raman1309 added a commit to Raman1309/HacktoberFestContribute that referenced this issue Oct 26, 2019
Reverses the given string using Stack Data Structure. This solves rathoresrikant#576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants