forked from rathoresrikant/HacktoberFestContribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4029e5f
commit 1a171f9
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include<stdio.h> | ||
#include<string.h> | ||
|
||
//define maximum up to 20 | ||
#define MAX 20 | ||
|
||
int top = -1; | ||
char stack[MAX]; | ||
|
||
/*Begin of push*/ | ||
char push(char item) | ||
{ | ||
if(top == (MAX-1)) | ||
printf("Stack Overflow\n"); | ||
else | ||
stack[++top] =item; | ||
} | ||
/*End of push*/ | ||
|
||
/*Begin of pop*/ | ||
char pop() | ||
{ | ||
if(top == -1) | ||
printf("Stack Underflow\n"); | ||
else | ||
return stack[top--]; | ||
} | ||
/*End of pop*/ | ||
|
||
/*Begin of main*/ | ||
int main() | ||
{ | ||
char str[20]; | ||
int i; | ||
printf("Enter the string : " ); | ||
gets(str); | ||
for(i=0;i<strlen(str);i++) | ||
push(str[i]); | ||
for(i=0;i<strlen(str);i++) | ||
str[i]=pop(); | ||
printf("Reversed string is : "); | ||
puts(str); | ||
return 0; | ||
|
||
} |