码迷,mamicode.com
首页 > 其他好文 > 详细

队列的入队和出队操作

时间:2015-08-03 21:00:42      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
using namespace std;


typedef struct student{
int data;
struct student *next;
}node;
typedef struct linkqueue
{
node *first, *rear;
}queue;


//队列的入队
queue *insert(queue *HQ, int x)
{
node *s;
s = (node*)malloc(sizeof(node));
s->data = x;
s->next = NULL;
if (HQ->rear == NULL)
{
HQ->first = s;
HQ->rear = s;
}
else
{
HQ->rear->next = s;
HQ->rear = s;
}
}
//队列出队
queue *del(queue *HQ)
{
node *p;
int x;
if (HQ->first == NULL)
{
printf("\n yichu");
}
else
{
x = HQ->first->data;
p = HQ->first;
if (HQ->first == HQ->rear)
{
HQ->first = NULL;
HQ->rear = NULL;
}
else
{
HQ->first = HQ->first->next;
free(p);
}
return (HQ);
}
}





版权声明:本文为博主原创文章,未经博主允许不得转载。

队列的入队和出队操作

标签:

原文地址:http://blog.csdn.net/wangfengfan1/article/details/47261427

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!