leetcode 알고리즘 문제 -- 디자인 순환 대기 열
                                            
 1989 단어  일상 연습
                    
#include
using namespace std;
class MyCircularQueue {
public:
	/** Initialize your data structure here. Set the size of the queue to be k. */
	MyCircularQueue(int k)
	{
		deque_size = k;
		p = NULL;
		tail = NULL;
		head = NULL;
	}
	/** Insert an element into the circular queue. Return true if the operation is successful. */
	bool enQueue(int value)
	{
		if (isFull())
			return false;
		p = new Deque;
		p->x = value;
		p->next = NULL;
		if (isEmpty())
		{
			head = p;
			tail = p;
			head->next = tail;
			tail->next = head;
		}
		else
		{
			tail->next = p;
			p->next = head;
			tail = p;
		}
		return true;
	}
	/** Delete an element from the circular queue. Return true if the operation is successful. */
	bool deQueue() //      
	{
		if (isEmpty())
			return false;
		Deque * temp;
		if (head == tail)
		{
			delete tail;
			head = NULL;
			tail = NULL;
			p = NULL;
		}
		else
		{
			tail->next = head->next;
			delete head;
			head = tail->next;
		}
		return true;
	}
	/** Get the front item from the queue. */
	int Front()
	{
		if (isEmpty())
			return -1;
		return head->x;
	}
	/** Get the last item from the queue. */
	int Rear()
	{
		if (isEmpty())
			return -1;
		return tail->x;
	}
	/** Checks whether the circular queue is empty or not. */
	bool isEmpty() 
	{
		if (head == NULL)
			return true;
		else
			return false;
	}
	/** Checks whether the circular queue is full or not. */
	bool isFull() 
	{
		Deque * temp;
		int _count = 0;
		for (temp = head; temp != tail; temp = temp->next)
			_count++;
		return ++_count == deque_size;
	}
private:
	unsigned int deque_size;
	struct Deque
	{
		int x;
		Deque * next;
	}*p, *tail, *head;
};
 이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
leetcode 알고리즘 문제 -- 디자인 순환 대기 열텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.