-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3.Stack.c
More file actions
72 lines (72 loc) · 1.65 KB
/
3.Stack.c
File metadata and controls
72 lines (72 loc) · 1.65 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
#include <stdio.h>
#include<stdlib.h>
#define MAX 5
int top=-1,stk[MAX];
void push(){
if(top==MAX-1){
printf("\nStack Overflow\n");
return;
}
int n;
printf("\nEnter no. to be pushed\n");
scanf("%d",&n);
stk[++top]=n;
}
void pop(){
if(top==-1)
printf("\nStack underflow\n");
else
printf("\nThe element being popped% d\n",stk[top--]);
}
void palindromeNo(){
int n,b,s=0,d;
printf("\nEnter the element to be checked for palindrome\n");
scanf("%d",&n);
b=n;
while(b!=0){
d=b%10;
s=s*10+d;
b=b/10;
}
if(s==n)
printf("\nPalindrome no\n");
else
printf("\nNot palindrome no\n");
}
void palindrome(){
int i;
for(i=0;i<=top/2;i++){
if(stk[i]!=stk[top-i]){
printf("\nNot a palindrom stack\n");
return;
}
}
printf("\nPalindrome Stack\n");
}
void display(){
int i=top;
printf("\nThe elements of the stack are\n");
for(i=top;i>=0;i--)
printf("%d ",stk[i]);
}
int main() {
int ch;
printf("\nMENU\n1.Push\n2.Pop\n3.Display\n4.Palindrome Stack\n5.Palindrome No\n6.Exit\n");
while(1){
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch){
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: palindrome();
break;
case 5: palindromeNo();
break;
case 6: exit(0);
}
}
}