数据结构-链表队列
来源:互联网 发布:淘宝天猫优惠券antlm 编辑:程序博客网 时间:2024/05/19 03:17
/*
* 队列的操作练习
* */
#include<stdio.h>
#include<malloc.h>
typedef int datatype;
//队列链表
typedef struct _node_
{
datatype data;
struct _node_ *next;
}linknode,*linklist;
//队列
typedef struct
{
linklist front,rear;
}linkqueue;
linkqueue *creat_empty_linkqueue()//创建队列
{
linkqueue *lq = NULL;
lq = (linkqueue *)malloc(sizeof(linkqueue));
lq->front = lq->rear = (linklist)malloc(sizeof(linknode));
lq->front->next = NULL;
return lq;
}
int empty_linkqueue(linkqueue *lq)//判空
{
if(lq->front == lq->rear)
{
return 1;
}
else
{
return 0;
}
//return lq->front == lq->rear;
}
int en_linkqueue(linkqueue *lq,datatype x)//入列
{
linklist q ;
q = (linklist)malloc(sizeof(linknode));
q->data = x ;
lq->rear->next = q;
lq->rear = q;
q->next = NULL;
return 1;
}
datatype de_linkqueue(linkqueue *lq)//出列
{
if(empty_linkqueue(lq))
{
return 0;
}
else
{
datatype temp;
linklist q;
q = lq->front;
lq->front = q->next;
temp = q->next->data;
free(q);
return temp;
}
}
int clear_linkqueue(linkqueue *lq)//清空队列
{
if(empty_linkqueue(lq))
{
return 0;
}
else
{
while(1)
{
if(empty_linkqueue(lq) != 1)
{
de_linkqueue(lq);
}
else
break;
}
}
}
int main(int argc,char *argv[])//主函数验证
{
linkqueue *lq = NULL;
lq = creat_empty_linkqueue();
printf("判断空:%d\n",empty_linkqueue(lq));
en_linkqueue(lq,200);
en_linkqueue(lq,300);
en_linkqueue(lq,500);
printf("判断空:%d\n",empty_linkqueue(lq));
printf("清空:%d\n",clear_linkqueue(lq));
en_linkqueue(lq,200);
printf("出列:%d\n",de_linkqueue(lq));
printf("判断空:%d\n",empty_linkqueue(lq));
return 0;
}
- 数据结构链表队列
- 数据结构-链表队列
- 数据结构----链表队列
- 数据结构:链表队列
- 数据结构:链表和队列
- 数据结构-链表队列实现
- 数据结构-队列-链表实现
- 数据结构---队列链表c实现
- 数据结构---队列的链表实现
- 【数据结构】队列-链表的实现
- 基础数据结构--队列链表实现
- 数据结构之队列的链表实现
- 数据结构之链表队列基本操作
- 数据结构-栈&队列&单向链表
- 使用链表结构构建队列数据结构
- 【数据结构】队列queue、普通链表list
- 双向链表实现数据结构中的队列
- 【数据结构】队列的链表实现
- Error: no matching symbolic information found
- android图表的实现
- ANDROID中LISTVIEW控件的使用
- 数据结构-链表环
- 科学计数法转换数值
- 数据结构-链表队列
- 开篇第一章
- ssh2做的一个批量操作
- python获取全部进程的CPU、内存使用率
- 全角转半角,arcgis中处理featureClass数据
- 我会安静的忘记你:伤感爱情空间日志
- 球钟问题到解决代码
- SAE python web.py bootstrap 开发记录
- 穷人与富人