Future of world with technology grow, thrive, empower yourself, one step at a time. Sucess unlocked.
The journey of self-motivation and personal growth is a lifelong path, filled with twists and turns, triumphs and setbacks. By embracing this journey, we can develop the skills, confidence, and resilience needed to achieve our goals and live a fulfilling life. I hope that my insights and experiences will inspire and motivate you to embark on your own journey of self-discovery and growth. Join me as I share insights, experiences, and practical tips on living a fulfilling life.
Monday, April 20, 2015
Tuesday, April 7, 2015
C program for parenthesized expression using stack
/*PARENTHESIZED EXPRESSION USING STACK */
#include<stdio.h>
#include<conio.h>
#define MAX 10
int top=-1;
int stack[MAX];
void push(char);
char pop();
void main()
{
char exp[MAX],ch;
int i,flag=1;
clrscr();
printf("\n Enter Infix Expression:-\n");
gets(exp);
i=0;
while(exp[i]!='\0')
{
if(exp[i]=='('||exp[i]=='{'||exp[i]=='[')
{
push(exp[i]);
}
if(exp[i]==')'||exp[i]=='}'||exp[i]==']')
{
ch=pop();
if(exp[i]==')'&&(ch=='{'||ch=='['))
{
flag=0;
}
if(exp[i]=='}'&&(ch=='('||ch=='['))
{
flag=0;
}
if(exp[i]==']'&&(ch=='('||ch=='{'))
{
flag=0;
}
}
i++;
}
if(top>=0)
{
flag=0;
}
if(flag==1)
{
printf("\n Valid Expression");
}
else
{
printf("\n Invalid Expression");
}
getch();
}
void push(char c)
{
if(top==MAX-1)
{
printf("\n stack is full");
}
else
{
top++;
stack[top]=c;
}
}
char pop()
{
char c;
if(top==-1)
{
printf("\n Stack is empty");
}
else
{
c=stack[top];
top--;
return c;
}
}
#include<stdio.h>
#include<conio.h>
#define MAX 10
int top=-1;
int stack[MAX];
void push(char);
char pop();
void main()
{
char exp[MAX],ch;
int i,flag=1;
clrscr();
printf("\n Enter Infix Expression:-\n");
gets(exp);
i=0;
while(exp[i]!='\0')
{
if(exp[i]=='('||exp[i]=='{'||exp[i]=='[')
{
push(exp[i]);
}
if(exp[i]==')'||exp[i]=='}'||exp[i]==']')
{
ch=pop();
if(exp[i]==')'&&(ch=='{'||ch=='['))
{
flag=0;
}
if(exp[i]=='}'&&(ch=='('||ch=='['))
{
flag=0;
}
if(exp[i]==']'&&(ch=='('||ch=='{'))
{
flag=0;
}
}
i++;
}
if(top>=0)
{
flag=0;
}
if(flag==1)
{
printf("\n Valid Expression");
}
else
{
printf("\n Invalid Expression");
}
getch();
}
void push(char c)
{
if(top==MAX-1)
{
printf("\n stack is full");
}
else
{
top++;
stack[top]=c;
}
}
char pop()
{
char c;
if(top==-1)
{
printf("\n Stack is empty");
}
else
{
c=stack[top];
top--;
return c;
}
}
Subscribe to:
Comments (Atom)
Featured posts
Ethiopian culture calendar language
Ethiopian culture, calendar, language The Ethiopian language, specifically Amharic , uses a script called Ge'ez script . It consists of...
Popular posts
-
Here's a simplified C program that simulates a basic indoor game, "Treasure Hunt". Treasure Hunt Game #include <stdio.h...
-
Solved practical slips of 12th Computer Science journal Program 1:- Write a function in C++ that exchanges data (passing by refer...