有没有人知道在哪里能找到用C语言编写的意大利面栈的示例代码?
有没有人知道在哪里能找到用C语言编写的意大利面栈的示例代码?
struct stack_item;
struct stack_item
{
stack_item *parent;
void *ptr_data;
};
stack_item *stack_pointer = null;
void push(stack_item *item)
{
if (stack_pointer == null)
item->parent = null;
else
item->parent = cur;
stack_pointer = item;
}
/* like push but doesn't update cur stack item to the one pushed, just add a child */
void push_parallel(stack_item *item)
{
if (stack_pointer == null)
{
stack_pointer = item;
item->parent = null;
}
else
item->parent = stack_pointer;
}
stack_item *pop()
{
if (stack_pointer == null)
{
printf("error: stack is empty.\r\n");
return null;
}
stack_item *current = stack_pointer;
stack_pointer = current->parent;
return current;
}