Last active
March 16, 2016 04:49
-
-
Save ObjSal/73e02dfb5eb4356b6b16 to your computer and use it in GitHub Desktop.
Queue using singly-linked list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Queue.h | |
// Data Structures | |
// | |
// Created by Salvador Guerrero on 3/15/16. | |
// Copyright © 2016 ByteApps. All rights reserved. | |
// | |
/* | |
* Queue using singly-linked list | |
* | |
* A samples can be found at: https://github.com/ObjSal/Data-Structures | |
*/ | |
#include "List.h" | |
#ifndef Queue_h | |
#define Queue_h | |
typedef struct list Queue; | |
void enqueue(Queue **queue, item_type item) | |
{ | |
list_insert(queue, item); | |
} | |
/* | |
* not performant at all, don't use in production, just for the demo. | |
*/ | |
Queue* _dequeue(Queue *queue_head, Queue *queue) | |
{ | |
if (queue == NULL) return NULL; | |
if (queue->next) | |
{ | |
return _dequeue(queue_head, queue->next); | |
} | |
Queue *predecessor_node = list_predecessor(queue_head, queue->item); | |
if (predecessor_node) | |
{ | |
predecessor_node->next = NULL; | |
} | |
return queue; | |
} | |
Queue* dequeue(Queue *queue) | |
{ | |
return _dequeue(queue, queue); | |
} | |
#endif /* Queue_h */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment