Created
January 25, 2019 17:48
-
-
Save emirozturk/1cfc721909f13c42ccc6c4e4541ac92f to your computer and use it in GitHub Desktop.
Veri Yapıları 3. Hafta 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> | |
struct dugum | |
{ | |
int sayi; | |
struct dugum* sonraki; | |
}typedef Dugum; | |
Dugum *kokDugum; | |
void listele() | |
{ | |
Dugum *temp = kokDugum; | |
while(temp!=NULL) | |
{ | |
printf("%d->",temp->sayi); | |
temp = temp->sonraki; | |
} | |
printf("NULL\n"); | |
} | |
void ekle() | |
{ | |
int eklenecek = 0; | |
printf("Eklenecek Sayi:");scanf("%d",&eklenecek); | |
Dugum *yeniDugum = (Dugum *)calloc(1,sizeof(yeniDugum)); | |
yeniDugum->sayi = eklenecek; | |
if(kokDugum == NULL) | |
kokDugum=yeniDugum; | |
else | |
{ | |
Dugum *temp =kokDugum; | |
while(temp->sonraki!=NULL) | |
temp = temp->sonraki; | |
temp->sonraki = yeniDugum; | |
} | |
} | |
void sil() | |
{ | |
int aranan = 0; | |
printf("Aranacak Sayi:");scanf("%d",&aranan); | |
Dugum *oncekiTemp,*temp; | |
oncekiTemp = temp=kokDugum; | |
while(temp!=NULL && temp->sayi !=aranan) | |
{ | |
oncekiTemp = temp; | |
temp = temp->sonraki; | |
} | |
if(temp!=NULL && temp!=kokDugum) | |
{ | |
oncekiTemp->sonraki = temp->sonraki; | |
free(temp); | |
} | |
else if(temp !=NULL) | |
{ | |
kokDugum=kokDugum->sonraki; | |
} | |
else | |
{ | |
printf("Aranan bulunamadi.\n"); | |
} | |
} | |
void ara() | |
{ | |
int aranan = 0; | |
int adim = 0; | |
printf("Aranan sayiyi giriniz:");scanf("%d",&aranan); | |
Dugum *temp = kokDugum; | |
while(temp!=NULL && aranan!=temp->sayi) | |
{ | |
adim++; | |
printf("Siradaki Sayi%d, Adim:%d, Aranan:%d. Bulunamadi.\n",temp->sayi,adim,aranan); | |
temp = temp->sonraki; | |
} | |
if(temp!=NULL) | |
printf("Siradaki Sayi%d, Adim:%d, Aranan:%d. En sonunda.\n",temp->sayi,adim,aranan); | |
else | |
printf("Bulunamadi\n"); | |
} | |
void menu() | |
{ | |
int secim = 0; | |
do | |
{ | |
listele(); | |
printf("1.Ekle\n"); | |
printf("2.Sil\n"); | |
printf("3.Ara\n"); | |
printf("4.Cikis\n"); | |
printf("Secim:");scanf("%d",&secim); | |
if(secim==1)ekle(); | |
if(secim==2)sil(); | |
if(secim==3)ara(); | |
if(secim==4)break; | |
}while(1); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
menu(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment