Community Sites
Create your own community website and start earning today !
It's Free !
Forum
Resources
Mentors
Projects
Entrance Exams
Question Papers
Colleges
Courses
Universities
Schools
Make Money
Communities
Members
Bookmarks
Polls
Fresher Jobs
Strange Photos
Academic Projects
New Member FAQ
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Anil
(103)
eldho
(90)
lukky
(72)
Last 7 Days
Saagar
(1818)
sunil
(1772)
satish
(1735)
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.
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
New version of encryption Virus
Your Name After Time at Taskbar
C++ program forswaping through template
How to Lock a Folder Using Notepad
C program-Linked Lists-Inserting a node by using recursive program
Watch TV Channels
Watch Asianet online
Kairali TV in Internet
Surya TV online
Amritha TV Channel
Contact Us
Editors
Privacy Policy
Terms Of Use
SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.