-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_String_Reverse.c
More file actions
75 lines (75 loc) · 1.33 KB
/
Stack_String_Reverse.c
File metadata and controls
75 lines (75 loc) · 1.33 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
75
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define size 100
char b[size][size];
int n,top=-1;
void push(char a[])
{
int i,j=0,l=0;
if(top == n-1)
{
printf("stack is full!!!\n");
return;
}
top++;
l = strlen(a)-1;
for(i=l;i>=0;i--)
{
b[top][j] = a[i];
j++;
}
b[top][j] = '\0';
}
void pop()
{
if(top == -1)
{
printf("stack is empty!!!\n");
return;
}
printf("popped element = %s\n",b[top--]);
}
void display()
{
int i;
if(top == -1)
{
printf("stack is empty!!!\n");
return;
}
for(i=top;i>=0;i--)
printf("%s\t",b[i]);
printf("\n");
}
int main()
{
int s;
char a[size];
printf("Enter the size of stack : ");
scanf("%d",&n);
while(1)
{
printf("\n0.exit\n1.push\n2.pop\n3.display\nEnter your choice : ");
scanf("%d",&s);
if(s == 0)
break;
switch(s)
{
case 1:
printf("Enter string : ");
scanf("%s",a);
push(a);
break;
case 2:
pop();
break;
case 3:
display();
break;
default:
printf("invalid choice!!!\n");
}
}
return 0;
}