-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_reverse.c
More file actions
74 lines (64 loc) · 1.08 KB
/
string_reverse.c
File metadata and controls
74 lines (64 loc) · 1.08 KB
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
//string reverse using stack
#include<stdio.h>
#include <string.h>
#define MAX 15
int top1 = -1,top2=-1;
int stack[MAX] ;
int minStack[MAX];
void push2(int ch){
if(top2 == MAX - 1){
printf("Stack Overflow");
return;
}
minStack[++top2] = ch;
}
void push1(int ch){
if(top1 == MAX - 1){
printf("Stack Overflow");
return;
}
if(top1 == -1){
push2(ch);
//push1(ch);
stack[++top1] = ch;
//top1++;
}
else{
stack[++top1] = ch;
if(minStack[top2]>ch){
push2(ch);
}
}
}
int pop1(){
if(top1 == -1){
return '\0';
}
else{
return stack[top1--];
}
}
int pop2(){
if(top2 == -1){
return '\0';
}
else{
return minStack[top2--];
}
}
int main()
{ //char str[MAX];
//stack[MAX] = ;
// while(top1 != -1 && top2 != -1){
// temp = pop1();
// if(temp < minStack[top2]){
// push2(temp);
// }
// }
//printf("%d ",minStack[top2]);
push1(69);
push1(12);
push1(20);
push1(1);
printf("%d",minStack[top2]);
}