我的盲点:将队列入队、出队的方向搞反,同时将队列中节点指针的指向弄反。
没有考虑队列出队后,该队列是否为空的情况。
入队时,队列为空要单独处理。
#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 =