Skip to content

Commit 7c858e5

Browse files
Create Reverse_a_string_using_STACK.c
1 parent 14bba55 commit 7c858e5

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Reverse_a_string_using_STACK.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ABC international is checking the company names of its client for palindrome. A string is said to be palindrome if both the input string and the reversed output string are one and the same. So ABC international needs to reverse the names of the companies they have. Write a program to reverse a string using stack implementation. Remember as stack uses LIFO concept the string pushed can be popped out in a reverse order.
2+
3+
// Constraint: String can be of size 10.
4+
5+
// Input: Input string S
6+
7+
// Output: Reverse of a string given as input or overflow if string is above size 10.
8+
9+
// Test Case 1:
10+
11+
// Input:
12+
13+
// madam
14+
15+
// Output
16+
17+
// madam
18+
19+
#include<stdio.h>
20+
#include<string.h>
21+
char s[100];
22+
int top=-1;
23+
void push(char e)
24+
{
25+
top++;
26+
s[top]=e;
27+
}
28+
void display()
29+
{
30+
while(top>=0)
31+
{
32+
printf("%c",s[top]);
33+
top--;
34+
}
35+
}
36+
int main()
37+
{
38+
char ch[100];
39+
scanf("%s",ch);
40+
for(int i=0;i<strlen(ch);i++)
41+
push(ch[i]);
42+
if(strlen(ch)>10)
43+
printf("Overflow");
44+
else
45+
display();
46+
}

0 commit comments

Comments
 (0)