Created
January 25, 2019 17:54
-
-
Save emirozturk/5e8142a086600f1797a829b9cbcd1267 to your computer and use it in GitHub Desktop.
Veri Yapıları Trie Uygulaması 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
struct dugum | |
{ | |
int frekans; | |
struct dugum *sonraki[256]; | |
}typedef Dugum; | |
Dugum *kok; | |
int dugumSayisi=0; | |
int kullanilanBellek=0; | |
int girilenBellek=0; | |
void bellekKullanimi() | |
{ | |
printf("Girilen verinin boyutu:%db\n",girilenBellek); | |
printf("Kullanılan Bellek:%db\n",kullanilanBellek); | |
printf("Dugum Sayisi:%d\n",dugumSayisi); | |
} | |
void ekle() | |
{ | |
char eklenecek[50]; | |
printf("Eklenecek:");scanf("%s",eklenecek); | |
Dugum *temp = kok; | |
for(int i=0;i<strlen(eklenecek);i++) | |
{ | |
girilenBellek++; | |
if(!temp->sonraki[eklenecek[i]]) | |
{ | |
Dugum *yeniDugum = (Dugum *)calloc(1,sizeof(Dugum)); | |
dugumSayisi++; | |
kullanilanBellek+=sizeof(Dugum); | |
temp->sonraki[eklenecek[i]]=yeniDugum; | |
} | |
temp = temp->sonraki[eklenecek[i]]; | |
} | |
temp->frekans++; | |
} | |
void ara() | |
{ | |
char aranan[50]; | |
printf("Aranan:");scanf("%s",aranan); | |
Dugum *temp = kok; | |
for(int i=0;i<strlen(aranan);i++) | |
{ | |
if(temp->sonraki[aranan[i]]) | |
temp = temp->sonraki[aranan[i]]; | |
else | |
break; | |
} | |
if(temp)printf("Frekans:%d",temp->frekans); | |
else printf("Bulunamadi"); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
kok = (Dugum *)calloc(1,sizeof(Dugum)); | |
kullanilanBellek+=sizeof(Dugum); | |
int secim = 0; | |
do | |
{ | |
bellekKullanimi(); | |
printf("1.Ekle\n"); | |
printf("2.Ara\n"); | |
printf("3.Cikis\n"); | |
printf("Secim:");scanf("%d",&secim); | |
if(secim == 1)ekle(); | |
if(secim ==2)ara(); | |
}while(secim!=3); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment