Forum
Resources
Mentors
Projects
Entrance Exams
Question Papers
Colleges
Courses
Universities
Make Money
Members
Bookmarks
Fresher Jobs
Funny Pictures
MCA Projects
New Member FAQ
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Syed
(555)
Saranya
(355)
Ramkumar
(315)
Last 7 Days
Syed
(1856)
sithananthan.k
(1806)
Shanthi M
(1384)
more...
Awards & Gifts
Online Exams
Aptitude Questions
General Aptitude Tests
Medical Entrance
Engineering Entrance
Bank Tests
TOEFL & IELTS Questions
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Paid Surveys
Make up to $50 per survey
C Program to check nesting of parentheses using stack
Posted Date: 24 Mar 2008 Resource Type:
Articles/Knowledge Sharing
Category:
Computer & Technology
Posted By:
ashish singh
Member Level:
Diamond
Rating:
Points
: 3
/* Program to check nesting of parentheses using stack */
#include
#define MAX 20
#define true 1
#define false 0
int top = -1;
int stack[MAX];
push(char);
char pop();
main()
{
char exp[MAX],temp;
int i,valid=true;
printf("Enter an algebraic expression : ");
gets(exp);
for(i=0;i
{
if(exp[i]=='(' || exp[i]=='{' || exp[i]=='[')
push( exp[i] );
if(exp[i]==')' || exp[i]=='}' || exp[i]==']')
if(top == -1) /* stack empty */
valid=false;
else
{
temp=pop();
if( exp[i]==')' && (temp=='{' || temp=='[') )
valid=false;
if( exp[i]=='}' && (temp=='(' || temp=='[') )
valid=false;
if( exp[i]==']' && (temp=='(' || temp=='{') )
valid=false;
}/*End of else */
}/*End of for*/
if(top>=0) /*stack not empty*/
valid=false;
if( valid==true )
printf("Valid expression\n");
else
printf("Invalid expression\n");
}/*End of main()*/
push(char item)
{
if(top == (MAX-1))
printf("Stack Overflow\n");
else
{
top=top+1;
stack[top] = item;
}
}/*End of push()*/
char pop()
{
if(top == -1)
printf("Stack Underflow\n");
else
return(stack[top--]);
}/*End of pop()*/
Responses
Author:
Prasad
18 May 2008
Member Level:
Gold
Points
: 2
Thanks for this useful program
Author:
Shanthi M
24 May 2008
Member Level:
Diamond
Points
: 2
It is useful for balancing parenthesis.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
C Program of input and output restricted dequeue using array
Previous Resource:
C Program for conversion of infix to postfix and evaluation of postfix
Return to Discussion Resource Index
Post New Resource
Category:
Computer & Technology
Post resources and
earn money
!
Related Resources
C Program for topological sorting
common language runtime(clr) in dot net.
Google and its Official Blogs
HOW TO LOCK THE FOLDER???
Hardware Interaction Through C-Function Address Founder and Tester
Contact Us
Privacy Policy
Terms Of Use
SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.