Pointer'lı Stack
Son Güncelleme : 22.10.2017
#include <stdio.h>
#include <stdlib.h>
// Pointerlı stack
// Stack'in düğüm yapısı
typedef struct stack {
int value;
struct stack *next;
}Snode;
// Düğüm oluşturma
Snode* s_p_get_node() {
return (Snode*)malloc(sizeof(Snode));
}
// İlk stack'i oluşturma
void s_p_create(Snode** stack, int value) {
if (*stack == NULL) {
(*stack) = s_p_get_node();
(*stack)->next = NULL;
(*stack)->value = value;
}
else
printf("\nStack already created (use s_p_push func.), nothing changed !");
}
// Eleman ekleme
void s_p_push(Snode* node, int value) {
if (node == NULL)
printf("\nThere is no stack [use (one-off) s_p_create func.], nothing changed !");
else {
Snode* p = s_p_get_node();
p->value = value;
p->next = node;
node = p;
}
}
// Eleman çıkarma
int s_p_pop(Snode* node) {
if (node == NULL) {
printf("\n%s", "There is no data, Nothing happend !");
// Eror code
return NULL;
}
Snode* p = s_p_get_node();
p = node;
node = node->next;
free(p);
return node->value;
Yorumlar
Yorum Gönder