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. 关于CATransform3D矩阵变换的简单解析

    关于CATransform3D矩阵变换的简单解析 效果图: 我能能够用上的CATransform3D其实很简单,并不复杂. CATransform3D有着4种东西我们可以设置. 1. 透视效果(由m3 ...

  2. join语句中on条件与where条件的区别

    大纲:on是在生成连接表的起作用,where是生成连接表之后对连接表再进行过滤 当使用left join时,无论on的条件是否满足,都会返回左表的所有记录,对于满足的条件的记录,两个表对应的记录会连接 ...

  3. 7 Dockerfile指令详解 && VOLUME 指令

    格式为: VOLUME ["<路径1>", "<路径2>"...] VOLUME <路径> 之前我们说过,容器运行时应该尽量 ...

  4. 沉淀再出发:xml的意义和存在的价值

    沉淀再出发:xml的意义和存在的价值 一.前言 学习了那么多的语言.框架.语法和基础知识,我们对于数据的理解或许有了一定的认识,但是如何描述.包装.传输.存储数据的手法和流程我们了解的或许并不多,其中 ...

  5. C/S架构的性能测试

    很多人关心LR在C/S架构上如何实施性能测试,我想根本原因在于两个方面,一是很多时候脚本无法录制,即LR无法成功调用被测的应用程序,二是测试脚本即使录制下来,可读性不强,往往不能运行通过,调试时无从下 ...

  6. Python中替换的三种方法

    strip()    replace()      re.sub() 1.replace()是python的内置函数,字符类型.replace(old,new) s1="你好2017&quo ...

  7. shell基础学习

    1. #! /bin/bash #设置只读变量,只读变量不可修改myUrl="http://www.baidu.com"readonly myUrl #删除变量,unset不能删除 ...

  8. vue-cli + webpack自动生成项目

    # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack palanWebsit ...

  9. win7装postgresql10.4

    第一步: 第二步: 第三步: 第四步: 第五步: 下载地址:https://get.enterprisedb.com/postgresql/postgresql-10.4-1-windows-x64. ...

  10. BZOJ 1295 最长距离 BFS+枚举

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1295 题目大意: windy有一块矩形土地,被分为 N*M 块 1*1 的小格子. 有 ...