mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 01:16:17 +01:00
b5706b2604
Fri Jan 22 11:58:13 EST 1999 Jeff Garzik <jgarzik@pobox.com> * Makefile.am: Add gqueue.c * glib.h: Add GQueue struct and prototypes. Remove g_stack_free macro. * gqueue.c New file. Implementation of a queue ADT. * gstack.c: Rename _g_stack_free back to g_stack_free. * tests/Makefile.am, tests/stack-test.c: New test for GStack objects.
73 lines
899 B
C
73 lines
899 B
C
#ifdef HAVE_CONFIG_H
|
|
# include <config.h>
|
|
#endif
|
|
#include <glib.h>
|
|
|
|
/*
|
|
* GStack, opaque ADT with interface:
|
|
|
|
stack = g_stack_new ();
|
|
count = g_stack_size (stack);
|
|
|
|
g_stack_push (stack, data);
|
|
data = g_stack_pop (stack);
|
|
|
|
slist = g_stack_get_list (stack);
|
|
*/
|
|
|
|
GStack *
|
|
g_stack_new (void)
|
|
{
|
|
GStack *s;
|
|
|
|
s = g_new (GStack, 1);
|
|
if (!s)
|
|
return NULL;
|
|
|
|
s->list = NULL;
|
|
|
|
return s;
|
|
}
|
|
|
|
|
|
void
|
|
g_stack_free (GStack *stack)
|
|
{
|
|
if (stack) {
|
|
if (stack->list)
|
|
g_list_free (stack->list);
|
|
|
|
g_free (stack);
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
_g_stack_push (GStack *stack, gpointer data)
|
|
{
|
|
if (stack)
|
|
stack->list = g_list_prepend (stack->list, data);
|
|
}
|
|
|
|
|
|
gpointer
|
|
g_stack_pop (GStack *stack)
|
|
{
|
|
gpointer data = NULL;
|
|
|
|
if ((stack) && (stack->list)) {
|
|
GList *node = stack->list;
|
|
|
|
stack->list = stack->list->next;
|
|
|
|
data = node->data;
|
|
|
|
g_list_free_1 (node);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
|