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

代码还有些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. (2)RDD的基本操作

    一.map操作,map(Transform) 二.collect操作,collect(Action) 三.使用PairRDD来做计算,类似key-value结构 采用groupByKey来.将资料按照 ...

  2. JQuery获取ID含有特殊字符的DOM元素

    因为业务需要,DOM元素的ID被命名为"13/16(FCO26)",执行JQuery的DOM查询时,提示如下错误 Uncaught Error: Syntax error, unr ...

  3. 引入拦截器及swagger支持及解决redis无法初始化问题

    Springboot引入拦截器 自定义的拦截器类 Interceptor package cn.zytao.taosir.auth.config; import javax.annotation.Re ...

  4. 实现双向数据绑定mvvm

    实现双向数据绑定mvvm  

  5. Mybatis之MySql批量insert后返回主键

    需求:使用批量插入后,需要insert之后的每一条记录的ID 注意:Mybatis3.3.1的版本以后支持批量插入后返回主键ID 示例: domin.java: public class User { ...

  6. windows server 2008开机自动登陆无密码,关机不必写原因

    运行secpol.sec接下来,在弹出的“本地安全策略”对话框中,依次展开左边树图到“本地策略”-“安全选项”,在右边可以找到“交互式登录 无须按 Ctrl+Alt+Del”,双击该项设置为“已启用” ...

  7. apk去广告工具(利用apktool去除apk文件里的广告)

    基本知识 apk安装包的文件结构 以知名桌面软件“LauncherPro”为例,apk安装包文件目录: 文件目录如下: - META-INF - res - anim - color - drawab ...

  8. ZOJ 3435

    求(1,1,1)至(x,y,z)的互质个数. 即求(0,0,0)到(x-1,y-1,z-1)互质个数. 依然如上题那样做.但很慢...好像还有一个分块的思想,得学学. #include <ios ...

  9. NOIP2017提高组模拟赛4 (总结)

    NOIP2017提高组模拟赛4 (总结) 第一题 约数 设K是一个正整数,设X是K的约数,且X不等于1也不等于K. 加了X后,K的值就变大了,你可以重复上面的步骤.例如K= 4,我们可以用上面的规则产 ...

  10. 2435: [Noi2011]道路修建(树上操作)

    2435: [Noi2011]道路修建 题目:传送门 题解: 建完边之后以1为根建树,统计深度和各个点的子树大小(包括自己) 询问的时候:答案=长度*abs(n-深度大的点的子树大小*2) ans+= ...