Ala ala stack dinamis

 #include <stdio.h>

#include <stdlib.h>

typedef struct element

{

    int data;

    struct element * next;

}element;


typedef struct

{

    element * top;

}stack;

void empty(stack * s)

{

    s->top = NULL;

}


void push(int data,stack *s)

{

    element * baru = (element*)malloc(sizeof(element));

    baru->data = data;

    baru->next  = NULL;

    if(s->top == NULL)

    {

        baru->next = NULL;

    }else

    {

        baru->next = s->top;

    }

    s->top = baru;

}

void pop(stack * s)

{

    printf("%d",s->top->data);

    s->top = s->top->next;

}

int main()

{

    stack s;

    empty(&s);

    push(11,&s);

    push(12,&s);

    pop(&s);

    pop(&s);


}


Komentar

Postingan populer dari blog ini

Pentingnya Mendapatkan Sertifikasi di Bidang IT/Sebagai Programmer

Pengantar Java Swing Bagian 1

Pengenalan UML