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

代码还有些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. MySQL的几个重要配置参数详解

    .配置通用查询日志,需要在配置文件my.cnf中增加如下: () 在mysql的安装目录下,修改my.cnf配置文件,增加general_log = () 重启mysql,可执行命令/etc/init ...

  2. C# 基础复习 二 面向对象

    继承:子承父业  子:子类    父:父类    业:所有非私有成员 好处:代码的复用   继承后,实例化子类时,不止子类的构造,父类的构造也会执行,而且父类的构造先于子类的构造执行 即使在子类可以看 ...

  3. SOAP扩展PHP轻松实现WebService

    最近在一个PHP项目中对接外部接口涉及到WebService,搜索引擎上相关文章不是很多,找到的大都是引用一个号称很强大的开源软件 NuSOAP(下载地址:http://sourceforge.net ...

  4. [CodeForces] 543B Destroying Roads

    脑洞+暴力. 因为边权是1,所以bfs一下,O(n^2)求任意两点间最短路,再枚举. ans最大是\(dis_{s1,t1}+dis_{s2,t2}\) 再考虑有公共边的情况,一定存在两个点 u, v ...

  5. 【Latex常见问题总结】

    1. 非数学符号如max/min将下标放到正下方,这个问题折腾了很久, 下标不在正下方会带俩两个问题,一是有时候不够美观,二是会使得数学公式过长越界,需要换行. 解决方案:将符号转换为数学符号, \m ...

  6. Django -查询数据库相关操作

    一. 内置Admin 依赖APP: django.contrib.auth django.contrib.contenttypes django.contrib.messages django.con ...

  7. 紫书 例题8-1 UVa 120(构造法)

    #include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...

  8. VUE:事件处理和表单输入绑定

    事件处理 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  9. React入门基础

    1-react概念: React是一个用于构建用户界面的JavaScript库.React主要用于构建UI,很多人认为React是MVC中的V(视图).React起源于Facebook的内部项目.Re ...

  10. FastDFS 工具类实现文件上传_02

    一.jar 包 jar包下载:https://pan.baidu.com/s/1nwkAHU5 密码:tlv6 或者 下载工程,安装到 maven 本地仓库 工程下载:https://pan.baid ...