问题描述
编程实现队列的入队、出队操作
核心步骤
编程实现
#include <iostream>
#include <stdio.h>
#include <stdlib.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;
}
return HQ;
}
// 队列出队
queue *del(queue *HQ)
{
int x;
if (HQ->first==NULL)
{
printf("
溢出");
}
else
{
x = HQ->first->data;
if(HQ->first==HQ->rear)
{
HQ->first = NULL;
HQ->rear = NULL;
}
else
{
HQ->first = HQ->first->next;
}
return HQ;
}
}