数据结构与算法学习笔记——队列
2013-10-03 20:28
871 查看
/******************************************************** * Copyright(C): * Filename: queue.c * Author: * Version: * Date: * Description: ********************************************************/ #include <malloc.h> #include <stdio.h> #include "queue.h" //---------------------------------- // Enqueue() // // // void Enqueue(Queue *Q, ElementType X){ Q->size++; if ( ++(Q->rear) == Q->capacity ){ Q->rear = 0; } Q->array[ Q->rear ] = X; } //---------------------------------- // Dequeue() // // // ElementType Dequeue(Queue *Q){ Q->size--; if ( ++(Q->front) == Q->capacity ){ Q->front = 0; } return Q->array[ Q->front ]; } //---------------------------------- // DisposeQueue() // // // void DisposeQueue(Queue * Q){ Q->size = 0; Q->rear = -1; Q->front = -1; free(Q->array); } //---------------------------------- // InitQueue // // // int InitQueue(Queue *Q, int capacity){ if ( capacity < 1 ){ return -1; } Q->size = 0; Q->rear = -1; Q->front = -1; if ( (Q->array=(ElementType*)malloc(sizeof(ElementType)*capacity)) != NULL ){ Q->capacity = capacity; return 0; } return -1; } //---------------------------------- // IsEmptyQueue() // // // int IsEmptyQueue(Queue *Q){ return Q->size <= 0; } //---------------------------------- // IsFullQueue() // // // int IsFullQueue(Queue *Q){ return Q->size == Q->capacity; } //---------------------------------- // MakeEmptyQueue() // // // void MakeEmptyQeue(Queue *Q){ Q->size = 0; Q->front = 1; Q->rear = 0; }
/******************************************************** * Copyright(C): * Filename: queue.h * Author: * Version: * Date: * Description: ********************************************************/ #ifndef QUEUE_H #define QUEUE_H #define ElementType int typedef struct QueueRecord { int front; int rear; int size; int capacity; ElementType *array; }Queue; ElementType Dequeue(Queue *Q); void DisposeQueue(Queue *Q); void Enqueue(Queue* Q, ElementType X); void MakeEmptyQueue(Queue *Q); int InitQueue(Queue *Q, int capacity); int IsEmptyQueue(Queue *Q); int IsFullQueue(Queue *Q); #endif // QUEUE_H
相关文章推荐
- 【数据结构与算法学习笔记】PART3 线性结构(除向量外,数组、栈、队列、链表)
- 【算法学习笔记】06.数据结构基础 队列与堆栈初步
- 【算法学习笔记】06.数据结构基础 队列与堆栈初步
- [算法学习笔记]数据结构之栈和队列
- #数据结构与算法学习笔记#PTA10:层次遍历叶节点(JAVA)
- 数据结构与算法(c语言) 学习笔记——第三章练习
- #数据结构与算法学习笔记#剑指Offer1.5:二维数组中的查找(C++)
- 【算法学习笔记】11.数据结构基础 二叉树初步练习4
- 【学习笔记----数据结构05-栈与队列】
- 数据结构与算法学习笔记之--数据结构
- 数据结构与算法学习笔记--哈希表
- 数据结构与算法:python语言描述学习笔记Part2
- 数据结构与算法学习笔记——动态规划的入门与编程实现
- 4.[数据结构和算法分析笔记]队列 Queue
- 【算法学习笔记】12.数据结构基础 图的初步1
- [学习笔记]省选(算法?数据结构?)·线性基
- 【算法学习笔记】12.数据结构基础 图的初步1
- 数据结构与算法学习笔记——二叉树遍历(一)(递归、迭代)
- 慕课网学习笔记之数据结构队列(C++)
- 挑战程序设计竞赛2 数据结构与算法学习笔记