-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArananKelimeTekrariBagliListe.c
164 lines (144 loc) · 3.64 KB
/
ArananKelimeTekrariBagliListe.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int aranma_sayisi;
char kelime[30];
struct node *next;
struct node *prev;
} Bliste;
int boyut=0;
Bliste *Ekle(Bliste *root)
{
if(boyut < 20)
{
if(root == NULL)
{
root = (Bliste*)malloc(sizeof(Bliste));
printf("Aramak istediginiz kelimeyi giriniz : ");
fflush(stdin);
gets(root->kelime);
root->next = root;
root->prev = root;
boyut++;
return root;
}
Bliste *iter = root;
while(iter->next != root)
{
iter = iter->next;
}
iter->next = (Bliste*)malloc(sizeof(Bliste));
printf("Aramak istediginiz kelimeyi giriniz : ");
fflush(stdin);
gets(iter->next->kelime);
iter->next->next = root;
iter->next->prev = iter;
root->prev = iter->next;
boyut++;
return root;
}
else
{
printf("\nBagli listede yer kalmadi !!\n");
}
}
Bliste *Siralama(Bliste *root)
{
Bliste *temp;
int swap;
for(int i=0; i<boyut; i++)
{
temp=root;
while(temp->next != root)
{
if(temp->aranma_sayisi < temp->next->aranma_sayisi)
{
swap=temp->next->aranma_sayisi;
temp->next->aranma_sayisi=temp->aranma_sayisi;
temp->aranma_sayisi=swap;
}
temp=temp->next;
}
}
return root;
}
void Listele(Bliste *root)
{
Bliste *iter = root;
if(root == NULL)
return NULL;
while(iter->next != root)
{
printf("Kelime : %s\n", iter->kelime);
printf("Tekrar sayisi : %d\n", iter->aranma_sayisi);
printf("\n------------------------------\n");
iter = iter->next;
}
printf("Kelime : %s\n", iter->kelime);
printf("Tekrar sayisi : %d\n", iter->aranma_sayisi);
}
Bliste *KelimeAranmaSayilari(Bliste *root)
{
Bliste *iter = root;
while(iter->next != root)
{
iter->aranma_sayisi = Ara(root, iter->kelime);
iter = iter->next;
}
iter->aranma_sayisi = Ara(root, iter->kelime);
return root;
}
int Ara(Bliste *root, char kelime[30])
{
int size=0;
Bliste *iter = root;
if(root == NULL)
return NULL;
else if(strcmp(root->kelime, kelime) == 0)
size++;
while(iter->next != root)
{
if(strcmp(iter->next->kelime, kelime) == 0)
size++;
iter = iter->next;
}
return size;
}
int main()
{
int menu, sonuc;
Bliste *root = NULL;
char aranan[30];
printf("\n\n\t\t -- MENU -- \n\t----------------------------\n\t1)Ekle\n\t2)Listele\n\t----------------------------\n");
while(1 == 1)
{
printf("Menu seciniz : ");
scanf("%d", &menu);
printf("\n----------------------------\n");
switch(menu)
{
case 1:
printf("\nEKLEME\n\n");
root = Ekle(root);
root = KelimeAranmaSayilari(root);
break;
case 2:
printf("\nLISTELEME\n\n");
Listele(root);
break;
case 3:
printf("\nSIRALI LISTELEME\n");
root = Siralama(root);
Listele(root);
break;
case 0:
printf("\nCIKIS YAPILIYOR..\n\n");
exit(0);
default:
printf("\nGECERSIZ MENU SECIMI !!\n\n");
break;
}
}
return 0;
}