Advertisement

c++ 链表用于实现队列

阅读量:

在进行元素插入操作时,需特别关注一些特殊情况,如当队列处于空状态、仅包含一个元素,或是包含多个元素时,应分别采取对应的插入方式。

复制代码
    #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:
    	Queue(){
    		size = 0;
    		head = back = NULL;
    	}
    	bool empty(){
    		return size == 0;
    	}
    	Node* front(){
    		return head;
    	}
    	Node* push_back(int v

全部评论 (0)

还没有任何评论哟~