【数据结构】队列的出队和入队操作

本文探讨了队列的基本操作,包括出队和入队,强调了先进先出的原则。当队列为空或者仅有一个元素时,其状态有特定的表示方式。初始化队列时,务必注意对头指针的正确设置。
摘要由CSDN通过智能技术生成

队列的操作规则是先进先出,要注意一下,

1.队列为空

2.队列只有一个元素,即头尾指针都指向空 

3.初始化队列时,分配空间后不要忘记将头为指针置空

// 13_4.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>
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 *p = (node *)malloc(sizeof(node));
	p->data = x;
	p->next = NULL;
	if (NULL == HQ->rear)
	{
		HQ->first = p;
		HQ->rear = p;
	}
	else
	{
		HQ->rear->next = p;
		HQ->rear = p;
	}
	cout << HQ->rear->data << endl;
	return HQ;
}

queue *del(queue *HQ)
{
	node *p;
	int x;
	if (NULL == HQ)
	{
		cout << "Queue is null!" << endl;
	}
	else
	{
		p 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值