Created
January 7, 2018 16:29
-
-
Save meylady/5717edf5566f0d77e64564eb32774dd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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