#include <stdio.h>
#include <conio.h>
#include <string.h>
int top, ml;
//--------------------------------------------------------------------
int FULL(void) {
if (top>=ml) return 1;
else return 0;
}
//--------------------------------------------------------------------
int EMPTY(void) {
if (top<=0) return 1;
else return 0;
}
//--------------------------------------------------------------------
void POP(char &x, char S[]) {
if (EMPTY()) printf("\n!!! Girilen islem HATALI !!!\n");
else {
x = S[top];
top = top - 1;
}
}
//--------------------------------------------------------------------
void PUSH(char x, char S[]) {
if (FULL()) printf("\n!!! Girilen islem HATALI !!!\n");
else {
top = top + 1;
S[top] = x;
}
}
//--------------------------------------------------------------------
int i, hata;
char metin[50], k;
char Stack[50];
//--------------------------------------------------------------------
void Karsilastir(char sembol, char cikan);
void YiginKontrol();
void HataVar();
void HataYok();
//--------------------------------------------------------------------
void Kontrol(char sembol, int i)
{
switch(sembol)
{
case '(':
case '{':
case '[':
PUSH(metin
, Stack);
default :
switch(sembol)
{
case ')':
case '}':
case ']':
if (EMPTY() == 0)
{
POP(k, Stack);
Karsilastir(sembol, k);
}
else
hata+=1;
}
}
}
//--------------------------------------------------------------------
void Karsilastir(char sembol, char cikan)
{
switch(sembol)
{
case ')':
if (cikan=='(')
{
break;
}
else
{
HataVar(); break;
}
case '}':
if (cikan=='{')
{
break;
}
else
{
HataVar(); break;
}
case ']':
if (cikan=='[')
{
break;
}
else
{
HataVar(); break;
}
}
}
//--------------------------------------------------------------------
void HataVar()
{
hata+=1;
}
void HataKontrol()
{
if (EMPTY()==0 || hata>0)
printf("\n!!! Girilen islem HATALI !!!\n");
else
printf("\n!!! Girilen islem DOGRU tanimlanmistir !!!\n");
}
//--------------------------------------------------------------------
void main()
{
clrscr;
top = 0;
ml = sizeof(Stack);
printf("Infix Notasyonunda Parantez Kontrolu\n");
printf("------------------------------------\n");
printf("\nInfix: ");
scanf("%s", metin);
for (i=0; i<strlen(metin); i++)
{
Kontrol(metin, i);
}
HataKontrol();
getch();
}
kodu yazan arkadasım Mstfcck