相对而言,队列是比较简单的。

代码还有些warning,我改不动,要找gz帮忙。

 #include <stdio.h>

 typedef struct node
{
int data;
struct node* next;
}Node; typedef struct queue
{
Node* head;
Node* tail;
}Queue; void InitQueue(Queue*);
void EnQueue(Queue*, int);
int DeQueue(Queue* queue);
void PrintQueue(Queue* queue);
int IsNull(Queue* queue);
void DelQueue(Queue* queue); void DelQueue(Queue* queue)
{
while(queue->head != queue->tail)
{
DeQueue(queue);
} } void PrintQueue(Queue* queue)
{
if(IsNull(queue))
{
printf("empty queue.\n");
return ;
}
Node* curNode= queue->head->next;
while(curNode)
{
if(curNode->next !=NULL)
{
printf("%d==>", curNode->data);
}else
{
printf("%d ", curNode->data); }
curNode = curNode->next;
}
printf("\n"); } void InitQueue(Queue* queue)
{
queue->tail = (Node*)malloc(sizeof(Node));//warning
queue->tail->data = -;
queue->head = queue->tail;
queue->tail->next = NULL;
}
//入队列
void EnQueue(Queue* queue, int data)
{
Node * newNode = (Node*)malloc(sizeof(Node));//warning
newNode->data = data;
newNode->next = NULL;
queue->tail->next = newNode;//2b 这里漏了。。。导致链表连不上去
queue->tail = newNode;
} int DeQueue(Queue* queue)
{
int popValue = queue->head->data;
Node *popNode = queue->head;
queue->head = queue->head->next;
free(popNode);//warning
return popValue;
}
//1 means Null
int IsNull(Queue* queue)
{
return (queue->head == queue->tail);
} int main(void)
{
printf("Hello World!\n");
Queue queue;
InitQueue(&queue);
//printf("IsNull = %d\n", IsNull(&queue));
printf("enque 4 times and the elems: 1, 2, 3, 4\n");
EnQueue(&queue,);
//printf("IsNull = %d\n", IsNull(&queue));
EnQueue(&queue,);
EnQueue(&queue,);
EnQueue(&queue,);
PrintQueue(&queue);
printf("deque 1 times.\n");
DeQueue(&queue);
PrintQueue(&queue); printf("IsNull = %d\n", IsNull(&queue));
DelQueue(&queue);
printf("IsNull = %d\n", IsNull(&queue)); return ;
}

运行结果:

Hello World!
enque 4 times and the elems: 1, 2, 3, 4
1==>2==>3==>4
deque 1 times.
2==>3==>4
IsNull = 0
IsNull = 1  ////1 means Null


下个先写写排序吧,上次写了一部分,当然算法思想是参考其他人,我只是一个重造的菜狗。菜狗,菜狗,菜狗。。。,明天回家,很开心。晚上吃的太多,有点难受,@2016年7月29日00:44:26,睡不着。。。

队列(Queue)-c实现的更多相关文章

  1. Python进阶【第二篇】多线程、消息队列queue

    1.Python多线程.多进程 目的提高并发 1.一个应用程序,可以有多进程和多线程 2.默认:单进程,单线程 3.单进程,多线程 IO操作,不占用CPU python的多线程:IO操作,多线程提供并 ...

  2. Java中的队列Queue,优先级队列PriorityQueue

    队列Queue 在java5中新增加了java.util.Queue接口,用以支持队列的常见操作.该接口扩展了java.util.Collection接口. Queue使用时要尽量避免Collecti ...

  3. jquery 的队列queue

    使用示列代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  4. Windows Azure Service Bus (2) 队列(Queue)入门

    <Windows Azure Platform 系列文章目录> Service Bus 队列(Queue) Service Bus的Queue非常适合分布式应用.当使用Service Bu ...

  5. Windows Azure Service Bus (3) 队列(Queue) 使用VS2013开发Service Bus Queue

    <Windows Azure Platform 系列文章目录> 在之前的Azure Service Bus中,我们已经介绍了Service Bus 队列(Queue)的基本概念. 在本章中 ...

  6. (C#)使用队列(Queue)解决简单的并发问题

    (C#)使用队列(Queue)解决简单的并发问题 2015-07-16 13:04 13265人阅读 评论(8) 收藏 举报  分类: Asp.Net(8)  版权声明:本文为博主原创文章,未经博主允 ...

  7. STL中的单向队列queue

    转载自:http://blog.csdn.net/morewindows/article/details/6950917 stl中的queue指单向队列,使用时,包含头文件<queue>. ...

  8. java09 队列Queue与Deque

    队列Queue与Deque. Enumeration Hashtable与Hashtable子类Properties(资源配置文件) 引用类型(强.软.弱.虚)与WeakHashMap Identit ...

  9. 队列Queue和栈

    1.队列Queue是常用的数据结构,可以将队列看成特殊的线性表,队列限制了对线性表的访问方式,只能从线性表的一段添加(offer)元素, 从另一段取出(poll)元素,队列遵循先进先出的原则. 2.J ...

  10. 消息队列Queue大全

    消息队列Queue大全 (http://queues.io/) 作业队列,消息队列和其他队列.几乎所有你能想到的都在这. 关于 那里有很多排队系统.他们每个人都不同,是为解决某些问题而创建的.这个页面 ...

随机推荐

  1. Dobble的学习视频地址

    http://www.tebaidu.com/file-f698fb45eb1b5c59571936118968d86c89194311.html

  2. luoguP2742 【模板】二维凸包 / [USACO5.1]圈奶牛 二维凸包

    我们知道,纵坐标最小的点一定在凸包上(如果有多个,那它们都会被取到) 随便找一个纵坐标最小的点,将其他所有点按照这个点为原点极角排序,我们发现极角大的会在极角小的后面加入(感性认知一下) 考虑新(加入 ...

  3. 路飞学城Python-Day33

    1.简述计算机操作系统中的“中断”的作用? 为什么有中断? 现代操作系统一般都是采用基于时间片的优先级调度算法,把CPU的时间划分为很细粒度的时间片,一个任务每次只能时间这么多的时间,时间到了就必须交 ...

  4. 给iview组件select设置默认值

    1.首先,给select加一个v-model,如: <Select v-model="exam_name" > <Option v-for="(item ...

  5. [读书笔记] R语言实战 (二) 创建数据集

    R中的数据结构:标量,向量,数组,数据框,列表 1. 向量:储存数值型,字符型,或者逻辑型数据的一维数组,用c()创建 **  R中没有标量,标量以单元素向量的形式出现 2. 矩阵:二维数组,和向量一 ...

  6. [luogu] P4105 [HEOI2014]南园满地堆轻絮 (贪心)

    P4105 [HEOI2014]南园满地堆轻絮 题目描述 小 Z 是 ZRP(Zombies' Republic of Poetry,僵尸诗歌共和国)的一名诗歌爱好者,最近 他研究起了诗词音律的问题. ...

  7. VUE:内置指令与自定义指令

    VUE:内置指令与自定义指令 常用的内置指令 1)v:text 更新元素的 textContent 2)v-html 更新元素的 innerHTML 3)v-if 如果为true,当前标签才会输出到页 ...

  8. [HTML5] Inlining images with SVG and data URIs

    The main reason you want to do I"nlining images with SVG and data URIs" is to reduce http ...

  9. 零基础学python-5.2 数字表达式操作符

    表达式是处理数字最主要的工具 a=1#常量 a=a+1#表达式 操作符 操作符 描写叙述 yield 生成 器函数发送协议 lambda args:expression 生成匿名函数 x if y e ...

  10. 开心的小明(南阳oj49)(01背包)

    开心的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 小明今天非常开心.家里购置的新房就要领钥匙了,新房里有一间他自己专用的非常宽敞的房间.更让他高兴的是,妈妈 ...