-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Reversal.c
More file actions
44 lines (43 loc) · 830 Bytes
/
String_Reversal.c
File metadata and controls
44 lines (43 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// WAP TO REVERSE A STRING USING STACKS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define size 30
int top=-1,count=0;
char stack[size];
char output[size]; //STORES THE REVESRED STRING
void push(char temp){
if(top==size-1){
printf("Stack Overflow\n");
}
else{
stack[++top]=temp;
}
}
void pop(){
if(top==-1){
printf("Stack Underflow\n");
}
else{
output[count]=stack[top]; // THE POPPED CHARACTERS OF THE STRING ARE STORED IN THE OUTPUT ARRAY
top--;
count++;
}
}
int main(){
int i;
char input[size];
printf("Enter any string:\n");
gets(input);
for(i=0;i<strlen(input);i++){
push(input[i]);
}
for(i=0;i<strlen(input);i++){
pop();
}
printf("\nThe Reversed String: ") ;
for(i=0;i<strlen(input);i++){
printf("%c",output[i]);
}
return 0;
}