注意些插入元素时要注意特殊的情况,例如队列为空时,队列只有一个元素时,或队列有多个元素时分别要以怎样的方式插入。
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct Node{
int val;
Node* next;
Node(int v){
val = v;
next = NULL;
}
};
class Queue{
int size;
Node* head; //pointer to the font node
Node* back; //pointer to the least node
public