Showing posts with label programlama. Show all posts
Showing posts with label programlama. Show all posts
Kendisine gönderilen bir integer sayıyı yine kendisine gönderilen bağlı listede bulunduran elemanı silen fonksiyonun c kodu
void liste_eleman_sil(int silinecek,struct eleman **ListeBasi){
struct dugum *b = *ListeBasi;
struct dugum *a;
while(*BagliListe != NULL){
a = b;
b = b->sonraki;
}
if(b == NULL){
return;
}
else if(b == *ListeBasi){
*ListeBasi = (*ListeBasi)->sonraki;
}
else{
a->sonraki = b->sonraki;
}
free(b);
}
void liste_eleman_sil(int silinecek,struct eleman **ListeBasi){
struct dugum *b = *ListeBasi;
struct dugum *a;
while(*BagliListe != NULL){
a = b;
b = b->sonraki;
}
if(b == NULL){
return;
}
else if(b == *ListeBasi){
*ListeBasi = (*ListeBasi)->sonraki;
}
else{
a->sonraki = b->sonraki;
}
free(b);
}
Kendisine gönderilen bağlı listeyi ters çeviren yani tüm bağlantıları tersine çeviren fonksiyonun C kodu
void liste_ters_cevir(struct dugum **BagliListe){
struct dugum *a,*b;
a = NULL;
While(*BagliListe != NULL){
b = *BagliListe;
*BagliListe = (*BagliListe)->sonraki;
b->sonraki = a;
a = b;
}
*BagliListe = a;
}
void liste_ters_cevir(struct dugum **BagliListe){
struct dugum *a,*b;
a = NULL;
While(*BagliListe != NULL){
b = *BagliListe;
*BagliListe = (*BagliListe)->sonraki;
b->sonraki = a;
a = b;
}
*BagliListe = a;
}
Kendisine gönderilen bağlı listedeki en küçük elemanı geri döndüren fonksiyonun c kodu
struct dugum* EnKucukDugum(struct dugum *BagliListe){
struct dugum *EnKucuk = NULL;
struct dugum *ListedeGez = BagliListe;
int EnKucukDeger = ListedeGez->icerik;
While(ListedeGez != NULL){
if(ListedeGez->icerik <= EnKucukDeger){
EnKucukDeger = ListedeGez->icerik;
EnKucuk= ListedeGez;
}
ListedeGez = ListedeGez->sonraki;
return EnKucuk;
}
struct dugum* EnKucukDugum(struct dugum *BagliListe){
struct dugum *EnKucuk = NULL;
struct dugum *ListedeGez = BagliListe;
int EnKucukDeger = ListedeGez->icerik;
While(ListedeGez != NULL){
if(ListedeGez->icerik <= EnKucukDeger){
EnKucukDeger = ListedeGez->icerik;
EnKucuk= ListedeGez;
}
ListedeGez = ListedeGez->sonraki;
return EnKucuk;
}
Kendisine gönderilen ikili arama ağacındaki tek çocuk düğüme sahip olan düğümlerin sayısını veren fonksiyonun c kodu
int TekCocukluDugumSayisi(struct dugum *agac){
if(agac->sag != NULL && agac->sol != NULL){
return TekCocukluDugumSayisi(agac->sol) + TekCocukluDugumSayisi(agac->sag);
}
else if(agac->sag == NULL && agac->sol != NULL){
return 1 + TekCocukluDugumSayisi(agac->sol);
}
else if(agac->sag != NULL && agac->sol == NULL){
return 1 + TekCocukluDugumSayisi(agac->sag);
}
else{
return 0;
}
}
Scala dilinde insert sıralama algoritması
object InsertSort extends App {
var dizi = Array(5,2,8,4,10,9,1,6,0,3,7)
var degistir = 0
var j = 0
for(i <- 0 to dizi.length-1){
j = i;
while(j > 0 && dizi(j) < dizi(j-1)){
degistir = dizi(j)
dizi(j) = dizi(j-1)
dizi(j-1) = degistir
j = j - 1
}
}
for(i <- 0 to dizi.length-1){
println(dizi(i))
}
}



