Skip to content

Instantly share code, notes, and snippets.

@emineker
Created November 22, 2011 19:55
Show Gist options
  • Save emineker/1386731 to your computer and use it in GitHub Desktop.
Save emineker/1386731 to your computer and use it in GitHub Desktop.
%100 yerli malı listeleme
#include <stdio.h>
#include <stdlib.h>
struct list {
int x;
struct list *next;
};
struct list *head;
int *toplam = 0;
void
list_add(int x)
{
struct list *new;
new = (struct list *)malloc(sizeof(struct list));
new->x = x;
new->next = head;
head = new;
}
void
list_free(void)
{
struct list *S, *tut_kacmasin;
for (S = head; S ; S = tut_kacmasin) {
tut_kacmasin = S->next;
free(S);
}
}
void
list_gez(void (*func)(struct list *S))
{
struct list *S;
for (S = head; S ; S = S->next) {
if (!S->x) {
printf("boş ya lan gerizekalı...\n");
return;
}
func(S);
}
}
void
print_item(struct list *S)
{
printf("x değeri: %d\n", S->x);
}
void
list_sum(struct list *S)
{
toplam += S->x;
printf("eklenecek sayı %d,toplam şu an: %d\n", S->x, toplam);
}
int
main(void)
{
// bir iki sayı ekle
list_add(3);
list_add(5);
list_add(7);
list_add(9);
// listeyi yazdıralım
list_gez(print_item);
// listeyi topla müdür
list_gez(list_sum);
// toplamı yaz bakem
printf("liste toplamı: %d\n", toplam); // o değil de sen niye 96 üretiyon lan!
// listeyi boşalt
list_free();
// listenin boş olması gerek ama yine de kontrol et
list_gez(print_item);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment