Chinaunix首页 | 论坛 | 博客
  • 博客访问: 693488
  • 博文数量: 152
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1793
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-12 12:26
个人简介

相信自己,只有不想做的,没有做不到的。

文章分类

全部博文(152)

文章存档

2021年(1)

2015年(2)

2014年(74)

2013年(75)

分类: LINUX

2013-10-27 21:33:38

#include
#include

/**************************队列***********************/
typedef struct 
{
struct node *front;
struct node *rear;
}LinkQueue;




LinkQueue *create_empty_queue()
{
struct node *head;
LinkQueue *q;


head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;


q = (LinkQueue *)malloc(sizeof(LinkQueue));
q->front = q->rear = head;


return q;
}


int is_empty_queue(LinkQueue *q)
{
return q->front == q->rear ? 1 : 0;
}


int EnterQueue(LinkQueue *q,DATATYPE data)
{
struct node *temp;


temp = (struct node *)malloc(sizeof(struct node));
temp->data = data;
temp->next = NULL;


q->rear->next = temp;
q->rear = temp;


return 0;
}


DATATYPE DeleteQueue(LinkQueue *q)
{
struct node *temp;


temp = q->front;
q->front = temp->next;
free(temp);


return q->front->data;
}

//这是一个队列和链表的结合  在实际中也较多,所以链表的概念要很熟悉,用的也是最多的。
阅读(955) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~