Skip to content

Instantly share code, notes, and snippets.

@meylady
Created January 7, 2018 16:29
Show Gist options
  • Save meylady/5717edf5566f0d77e64564eb32774dd5 to your computer and use it in GitHub Desktop.
Save meylady/5717edf5566f0d77e64564eb32774dd5 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <algorithm>
using namespace std;
template <typename T>
class _queue {
public:
class Node {
public:
T data;
Node *next;
Node() {}
Node(T data) :data(data),next(NULL){}
};
Node *Front = NULL;
Node *Rear = NULL;
int _size = 0;
void push(T data) {
Node *newNode = new Node(data);
_size++;
if (Front == 0) {
Front = Rear = newNode;
}
else {
Rear->next = newNode;
Rear = newNode;
}
}
void pop() {
if (_size == 0)return;//오류
_size--;
Node *temp = Front;
Front = temp->next;
delete temp;
}
bool empty() {
return size == 0;
}
T front() {
return Front->data;
}
int size() {
return _size;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment