What is the missing code ??
Code:
#include "stdafx.h"
#include < string >
void check()
{
int stackSize = input.length();
bool isError = false;
for(int j=0; j<input.length(); j++)
{
char ch = input[j];
switch(ch)
{
case '{':
case '[':
case '(':
push(ch);
break;
case '}':
case ']':
case ')':
if( !isEmpty() )
{
char chx = pop();
if( (ch=='}' && chx!='{') ||
(ch==']' && chx!='[') ||
(ch==')' && chx!='(') )
{
isError = true;
printf("Mismatched delimeter: %c at %d",ch,j);
printf("\n");
}
}
else
{
isError = true;
printf("Misplaced delimeter: %c at %d",ch,j);
printf("\n");
}
break;
default:
break;
}
}
if( !isEmpty() )
printf("Missing right delimeter\n");
else if( !isError )
printf("OK!!\n");
}
int main()
{
string input;
while(true)
{
printf("\nEnter string containing delimiters (no whitespace): ");
scanf("%s",input);
if( input.length() == 1 )
break;
check();
}
return 0;
}