-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathreverse string using stack.c
89 lines (62 loc) · 1.38 KB
/
reverse string using stack.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define MAX_SIZE 101
int A[MAX_SIZE],B[MAX_SIZE] ;
int top=-1;
int top2=-1;
void push(char x){
if(top == MAX_SIZE-1){
printf("Error! Stack Overflow!\n");
}
top++;
A[top]=x;
}
void print(){
for(int i=0;i<=top;i++){
printf(" %c ",A[i]);
}
printf("\n");
}
void print2(){
for(int i=0;i<=top2;i++){
printf(" %c ",B[i]);
}
printf("\n");
}
void reversePush(char x){
if(top2 == MAX_SIZE-1){
printf("Error! Stack Overflow!\n");
}
top2++;
B[top2]=x;
}
int main()
{
char str[100];
printf("Enter String: ");
scanf("%[^\n]%*c", str);
for(int i=0;i<strlen(str);i++){
push(str[i]);
}
// push('M');
// push('4');
// push('1');
// push('6');
print();
int counter=top;
for(int i=0;i<=counter;i++){
reversePush(A[top]);
top--;
}
print2();
//// push and pop in stack
//sort stack with recursion and without recursion
////reverse a stack
//tower of hanoi
////reverse a string using a stack
//check whether the 2 expressions in the brackets are same or not
////implement conversion of infix to postfix
//check whether the parenthesis are balanced or not in the given expression
return 0;
}