Академический Документы
Профессиональный Документы
Культура Документы
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 50
int stack[MAX];
void push(char);
void pop();
void main()
int i, choice;
char s[MAX], b;
while (1)
printf("1-enter string\n2-exit\n");
scanf("%d", &choice);
switch (choice)
case 1:
printf("Enter the String\n");
scanf("%s", s);
b = s[i];
push(b);
if (stack[top] == stack[front])
pop();
front++;
else
break;
if ((strlen(s) / 2) = = front)
front = 0;
top = -1;
break;
case 2:
exit(0);
default:
void push(char a)
top++;
stack[top] = a;
void pop()
top--;
Program Explanation
2. Load each character of the array s[] into the array stack[].
3. Use variables front and top to represent the last and top element of the array stack[].
4. Using for loop compare the top and last element of the array stack[]. If they are equal, then delete the
top element, increment the variable front by 1 and compare again.
5. If they are not equal, then print the output as “It is not a palindrome”.
6. Compare the elements in the steps 4-5 upto the middle element of the array stack[].
advertisement
1-enter string
2-exit
madam
madam is palindrome
1-enter string
2-exit
ugesh
1-enter string
2-exit
1
Enter the String
abccba
abccba is palindrome
1-enter string
2-exit
abdbca
1-enter string
2-exit
Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms
If you wish to look at other example programs on Stacks & Queues, go to C Programming Examples on
Stacks & Queues. If you wish to look at programming examples on all topics of C, go to C Programming
Examples.
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at
Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency
developments in these areas. He lives in Bangalore and delivers focused training sessions to IT
professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage,
Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI &
Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter
Best Careers
Developer Tracks
SAN Developer
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our
Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle,
Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio,
Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata
VSNL, Mindtree, Cognizant and Startups.
Best Trainings
SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
India Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
About Sanfoundry
About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
Sponsored
Advertisement
Sponsored
Advertisement