answersLogoWhite

0

/*Linked List Implementation of STACK*/

/*Checking of parenthesis in expressions*/

#include<conio.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define M 100

typedef struct node *nd;

struct node

{

char p;

nd next;

}NODE;

void getExpression(char expr[]);

void checkParenthesis(char expr[],int *);

void dispResult(int);

nd top,bottom;

int main(void)

{

char expr[M];

int r;

getExpression(expr);

checkParenthesis(expr,&r);

dispResult(r);

return 0;

}

void getExpression(char expr[])

{

clrscr();

printf("Input an expression: ");

gets(expr);

}

void checkParenthesis(char expr[],int *r)

{

int f=0,l,i;

char e;

nd tp,t;

top = NULL;

bottom = NULL;

l = strlen(expr);

for(i=0;i<l;i++)

{

e=expr[i];

if(e == '(')

{

tp = malloc(sizeof(NODE));

tp->p=e;

if((top==NULL) && (bottom==NULL))

{

tp->next = NULL;

top = tp;

bottom = tp;

}

else

{

tp->next=top;

top=tp;

tp=NULL;

}

}

else if(e==')')

{

if(top==bottom)

{

if(top==NULL)

{

f=1;

break;

}

else

{

top=NULL;

bottom=NULL;

}}

else

{

t=top;

top=top->next;

t->next=NULL;

}

}

}/*end of for loop*/

if(top != NULL)

f=1;

*r=f;

}/*end of function checkParenthesis*/

void dispResult(int r)

{

clrscr();

if(r==0)

printf("The expression has a balance parentheses.");

else if(r>0)

printf("Unbalanced parentheses.");

getch();

}

/*

if(top==bottom)

{

top=NULL;

bottom=NULL;

}

else

{

if((top==NULL)&&(bottom==NULL))

{

f=1;

break;

}

else

{

t =top;

top = top->next;

t->next = NULL;

}

}

}

*/

/*eahjie*/

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

Example program arrays in turbo c plus plus?

Yes, you can use for-loop in a C program compiled by Turbo C.


What are the program of turbo pascal?

tagprice


What is name of the software in which you create program?

Turbo c3 or Turbo c4. R.P. Hammad Khan_Haider...


What are examples of turbo c?

1. Turbo C is an example of Integrated Developing Environment. 2. Turbo C has example programs, the most important is bgidemo.c


Basic parts of TURBO C program?

Editor - edits text Compiler - compiles the program Linker - links the program Debugger - helps finding bugs


How can you use turbo c in Window7?

With program DosBox,


How do you load a program in turbo c?

File/Open


Who is the founder of turbo c program?

Turbo c program is from Borland which is an integrated development environment and a computer language. Some of the parts of turbo c were incorporated from the wizard c in 1987, but it was first developed by Dennis Ritchie in 1970.


What are the Examples of Turbo Pascal 5.5?

They are example programs written in Turbo Pascal.


What has the author Eric P Bloom written?

Eric P. Bloom has written: 'The Turbo C++ trilogy' -- subject(s): C (Computer program language), C++ (Computer program language), Turbo C (Computer file), Turbo C++ 'Turbo C Plus Plus Trilogy' 'The C trilogy' -- subject(s): C (Computer program language)


Do a program with turbo pascal to print the alphabet backward?

Turbo Pascal is a style of computer programming. This type of writing language can be used to create a program that prints the alphabet backwards.


What is turbo c programm?

BGIDEMO.C is an example.