Skip to content

Instantly share code, notes, and snippets.

@abhilash0001
Created January 14, 2020 18:05
Show Gist options
  • Save abhilash0001/a57f331244db388117b396e15311b408 to your computer and use it in GitHub Desktop.
Save abhilash0001/a57f331244db388117b396e15311b408 to your computer and use it in GitHub Desktop.
public static string reverseString(string str)
{
return !string.IsNullOrEmpty(str) ? reverse(str) : string.Empty;
}
private static string reverse(string str)
{
var stk = new Stack();
for (int i = 0; i < str.Length; i++)
{
stk.push(str[i]);
}
int k = 0;
while(stk.count > 0)
{
str[k++] = stk.top();
stk.pop();
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment