-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYiginIleParantezKontrol.c
116 lines (103 loc) · 2.15 KB
/
YiginIleParantezKontrol.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <stdlib.h>
#define N 100
typedef struct Yigin
{
int indis;
char eleman[N];
} Yiginlar;
Yiginlar *iter = NULL;
Yiginlar *YiginOlustur()
{
Yiginlar *yeni_yigin;
yeni_yigin = (Yiginlar*)malloc(sizeof(Yiginlar));
yeni_yigin->indis=0;
return yeni_yigin;
}
int YiginBosMu(Yiginlar *yeni_yigin)
{
if(yeni_yigin->indis == 0)
return -1;
else
return 1;
}
int YiginDoluMu(Yiginlar *yeni_yigin)
{
if(yeni_yigin->indis >= N)
return -1;
else
return 1;
}
void YiginaEkle(Yiginlar *yeni_yigin, char ekle)
{
if(YiginDoluMu(yeni_yigin) == -1)
{
printf("Yigin dolu !\n");
getch();
return -1;
}
else
{
yeni_yigin->eleman[yeni_yigin->indis] = ekle;
yeni_yigin->indis++;
}
}
void YigindanCikar(Yiginlar *yeni_yigin)
{
char cikan;
if(YiginBosMu(yeni_yigin) == -1)
{
printf("Yigin bos !\n");
getch();
return -1;
}
else
{
yeni_yigin->indis--;
yeni_yigin->eleman[yeni_yigin->indis];
}
}
int ParantezKontrol(Yiginlar *yeni_yigin, char *islem)
{
int i;
for(i=0; i<strlen(islem); i++)
{
if(islem[i] == '(')
YiginaEkle(yeni_yigin, islem[i]);
else
{
if(islem[i] == ')')
if(YiginBosMu(yeni_yigin) == -1)
return -1;
else
YigindanCikar(yeni_yigin);
}
}
if(YiginBosMu(yeni_yigin)!= -1)
return 0;
else
return 1;
}
int main()
{
Yiginlar *yeni_yigin = YiginOlustur();
printf("\nYeni yigin olustu.\n");
int i;
char islem[100];
printf("Kontrol stringi : ");
scanf("%s", islem);
i = ParantezKontrol(yeni_yigin, islem);
switch(i)
{
case -1:
printf("\nHata : Acma parantezi eksik !.\n");
break;
case 0:
printf("\nHata : Kapatma parantezi eksik !.\n");
break;
case 1:
printf("\nHata Yok..\n");
break;
}
return 0;
}