我的盲点:将队列入队、出队的方向搞反,同时将队列中节点指针的指向弄反。
没有考虑队列出队后,该队列是否为空的情况。
入队时,队列为空要单独处理。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
//Notice:队列的数据结构组成,先入队列(即出队列部分)部分为头(first),后入队列部分为尾(rear),队列的链表指针形式是从头指向尾。
// ->(入队列) node1<-node2 <- node3 <- ....<-noden ->(出队列)
// 1 1
// rear first
typedef struct Node
{
int data;
struct Node *next;
}node;
typedef struct Queue //notice :队列的数据结构只是包括两个节点指针(头和尾);
{
node* first;
node* rear;
}queue;
//队列的插入操作。注意:队列是从rear部插入
queue* insert(queue* My_queue,int x)
{
node* s;
s = (node*)malloc(sizeof(node));
s->data = x;
s->next = NULL;
//分为队列为

本文聚焦程序员面试中的数据结构基础,重点讨论队列的入队和出队操作。指出常见错误,包括混淆入队、出队方向以及忽视队列空状态的处理。强调在入队时,应对队列为空的情况进行特殊处理。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



