QUEUE DINAMIS
#include <stdio.h>
#include <stdlib.h>
typedef struct element
{
int data;
struct element * next;
}element;
typedef struct
{
element * top;
element * tail;
}queue;
void empty(queue * s)
{
s->top = NULL;
}
void push(int data,queue *q)
{
element * baru = (element*)malloc(sizeof(element));
baru->data = data;
baru->next = NULL;
if(q->top == NULL)
{
q->top = baru;
}else
{
q->tail->next = baru;
}
q->tail = baru;
}
void pop(queue * q)
{
printf("%d",q->top->data);
q->top = q->top->next;
}
int main()
{
queue s;
empty(&s);
push(11,&s);
push(12,&s);
pop(&s);
pop(&s);
}
Komentar
Posting Komentar