Skip to content

Instantly share code, notes, and snippets.

@ObjSal
Last active March 16, 2016 04:19
Show Gist options
  • Save ObjSal/2444540da062e837ff9a to your computer and use it in GitHub Desktop.
Save ObjSal/2444540da062e837ff9a to your computer and use it in GitHub Desktop.
Stack using singly-linked list
//
// Stack.h
// Data Structures
//
// Created by Salvador Guerrero on 3/15/16.
// Copyright © 2016 ByteApps. All rights reserved.
//
/*
* Stack using singly-linked list
*
* A samples can be found at: https://github.com/ObjSal/Data-Structures
*/
#include "List.h"
#ifndef Stack_h
#define Stack_h
typedef struct list Stack;
void stack_push(Stack **stack, item_type item)
{
list_insert(stack, item);
}
Stack* stack_pop(Stack **stack)
{
Stack *popped_node = *stack;
*stack = (*stack)->next;
popped_node->next = NULL; // this is now a standalone node.
return popped_node;
}
#endif /* Stack_h */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment