Deque ADT接口 DEQUEUE.h:

 #include <stdlib.h>
#include "Item.h" typedef struct DEQUEUEnode *link;
struct DEQUEUEnode
{
Item item;
link next;
link last;
}; void DEQUEUEinit(int);
void DEQUEUEerror(void);
Item DEQUEUEheadget(void);
Item DEQUEUEtailget(void);
void DEQUEUEheadput(Item);
void DEQUEUEtailput(Item);
int DEQUEUEisEmpty(void);
int DEQUEUEisFull(void);

Deque ADT接口实现 DEQUEUE.c:

 static link head,tail;
static int N; //备用 void DEQUEUEinit(int maxN)
{
head=malloc(sizeof(*head));
tail=head;
tail->next=NULL;
tail->last=NULL;
head->next=NULL;
head->last=NULL;
N=maxN;
}
void DEQUEUEerror(void)
{
printf("节点为空或节点已满");
exit();
}
Item DEQUEUEheadget(void)
{
Item temp;
temp=head->item;
head=head->next;
free(head->last);
head->last=NULL;
return temp;
}
Item DEQUEUEtailget(void)
{
Item temp;
tail=tail->last;
temp=tail->item;
free(tail->next);
tail->next=NULL;
return temp;
}
void DEQUEUEheadput(Item value)
{
head->last=malloc(sizeof(*head));
if(DEQUEUEisFull())
DEQUEUEerror();
head->last->next=head;
head=head->last;
head->item=value;
head->last=NULL;
}
void DEQUEUEtailput(Item value)
{
tail->item=value;
tail->next=malloc(sizeof(*head));
if(DEQUEUEisFull())
DEQUEUEerror();
tail->next->last=tail;
tail=tail->next;
tail->next=NULL;
}
int DEQUEUEisEmpty(void)
{
if(head==NULL&&tail==NULL)
return ;
return ;
}
int DEQUEUEisFull(void)
{
if((head==NULL&&tail!=NULL)||(head!=NULL&&tail==NULL))
return ;
return ;
}

Item.h:

1 typedef char Item;

主程序 main.c:

 #include <stdio.h>

 int main(void)
{
int N; printf("输入需要申请内存大小:");
if(scanf("%d", &N))
DEQUEUEinit(N);
else
DEQUEUEerror();
getchar();
printf("输入%d个字符",N);
printf("('+'从队头get '*'从队尾get '大写字母'"
"从队头put '小写字母'从队尾put):\n"); while((N=getchar())!='\n')
{
switch(N)
{
case '+':
putchar(DEQUEUEheadget());
break;
case '*':
putchar(DEQUEUEtailget());
break;
default:
if(N>&&N<)
DEQUEUEheadput(N);
else
DEQUEUEtailput(N);
}
} return ;
}

双端队列 ADT接口 链表实现的更多相关文章

  1. 双端队列 ADT接口 数组实现

    Deque ADT接口 DEQUEUE.h: #include <stdlib.h> #include "Item.h" void DEQUEUEinit(int); ...

  2. FIFO队列 ADT接口 链表实现

    FIFO.h (接口) #include "Item.h" void QUEUinit(int); int QUEUempty(void); void QUEUput(Item); ...

  3. 自己动手实现java数据结构(四)双端队列

    1.双端队列介绍 在介绍双端队列之前,我们需要先介绍队列的概念.和栈相对应,在许多算法设计中,需要一种"先进先出(First Input First Output)"的数据结构,因 ...

  4. 用Python实现的数据结构与算法:双端队列

    一.概述 双端队列(deque,全名double-ended queue)是一种具有队列和栈性质的线性数据结构.双端队列也拥有两端:队首(front).队尾(rear),但与队列不同的是,插入操作在两 ...

  5. Python实现的数据结构与算法之双端队列详解

    一.概述 双端队列(deque,全名double-ended queue)是一种具有队列和栈性质的线性数据结构.双端队列也拥有两端:队首(front).队尾(rear),但与队列不同的是,插入操作在两 ...

  6. Java 双端队列接口 Deque

    Deque 是一种支持在两端进行操作的线性结构,包含了栈和队列的功能.Java 中建议使用 Dqueue 的实现来替代遗留的 Stack 类.本文将介绍 Deque 提供的主要 API. 双端操作 A ...

  7. PAT 甲级 1074 Reversing Linked List (25 分)(链表部分逆置,结合使用双端队列和栈,其实使用vector更简单呐)

    1074 Reversing Linked List (25 分)   Given a constant K and a singly linked list L, you are supposed ...

  8. 用python实现栈/队列/双端队列/链表

    栈是元素的有序集合,添加操作与移除操作都发生在其顶端,先进后出栈操作:创建空栈,增删(顶端),查(顶端元素,元素个数,是否为空)应用:将十进制数转换成任意进制数 class Stack: # 用列表创 ...

  9. Java 集合深入理解(10):Deque 双端队列

    点击查看 Java 集合框架深入理解 系列, - ( ゜- ゜)つロ 乾杯~ 什么是 Deque Deque 是 Double ended queue (双端队列) 的缩写,读音和 deck 一样,蛋 ...

随机推荐

  1. Python学习---DjangoForm的总结大全

    DjangoForm基础知识总结 1.Form是什么东西? 用于验证用户请求数据合法性的一个组件 2. Django的Form的实现步骤: a. 创建一个验证用户请求的模板 from django i ...

  2. Windows Server、 Windows 区别

    今天脑补了普通Windows 操作系统与Windows Server区别,感觉清楚了很多. Microsoft WindowsServer,是美国微软公司研制的一套操作体系,它面世于1985年,起先仅 ...

  3. Mac OS 10.8 配置SVN服务器

    Mac 10.8开始,不再默认安装svn,需要自行安装 如果您安装了XCode,会随同安装svn 更省事的办法: 1.安装homebrew,看看官网 http://brew.sh/index_zh-c ...

  4. scala当中的特质trait

    1.将trait作为接口使用 Scala中的trait是一种特殊的概念: 首先先将trait作为接口使用,此时的trait就与Java中的接口 (interface)非常类似: 在trait中可以定义 ...

  5. Tomcat服务时区设置

    tomcat服务不设置时间,会自动取系统时间,根据项目部署服务器位置不同时间会有差别,统一设置tomcat服务集群时间为东八区时间,具体设置如下: 在tomcat目录的bin文件夹下,找到文件cata ...

  6. 虚拟机下的CentOS无法上网的解决办法

    1.首先保证虚拟机的网络适配器为NAT模式 2.设置虚拟机的“编辑”-->“虚拟网络编辑器”中的VMnet8的DHCP的设置两个选项都勾选上. 3.设置物理主机,保证虚拟网关的IP地址为自动获取 ...

  7. WebSocket消息推送

    WebSocket协议是基于TCP的一种新的网络协议,应用层,是TCP/IP协议的子集. 它实现了浏览器与服务器全双工(full-duplex)通信,客户端和服务器都可以向对方主动发送和接收数据.在J ...

  8. python 中的pipe

    from multiprocessing import Process,Queue,Pipe import os def f(q): # q.send([42,None,'hello']) print ...

  9. Input and Output-The input is all the sources of action for your app

    Programs take input and produce output. The output is the result of doing something with the input. ...

  10. 【[HEOI2016/TJOI2016]序列】

    压行真漂亮 首先这肯定是一个\(dp\)了 设\(dp_i\)表示\(i\)结尾的最长不下降子序列的长度 显然我们要找一个\(j\)来转移 也就是\(dp_i=max(dp_j+1)\) 那么什么样的 ...