Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define sz(v) (int)v.size()
- #define pb push_back
- using namespace std;
- class Node {
- public:
- int value;
- Node *next;
- public:
- Node(int value) {
- this->value = value;
- this->next = NULL;
- }
- };
- class List {
- public:
- Node *head, *tail;
- public:
- List() {
- this->head = this->tail = NULL;
- }
- void pop_front() {
- if (head == NULL) cout << "error\n";
- else if (head == tail) {
- cout << head->value << '\n';
- delete tail;
- head = tail = NULL;
- } else {
- cout << head->value << '\n';
- Node *node = head;
- head = node->next;
- delete node;
- }
- }
- void push_back(int value) {
- Node *node = new Node(value);
- if (head == NULL) head = node;
- if (tail != NULL) tail->next = node;
- tail = node;
- }
- };
- class Queue {
- private:
- List Node;
- int size;
- public:
- Queue() {
- size = 0;
- }
- int Queue_size() {
- return size;
- }
- void put(int num) {
- Node.push_back(num);
- size++;
- }
- void get() {
- Node.pop_front();
- if(size != 0){
- size--;
- }
- }
- };
- int main() {
- ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t;
- cin >> t;
- Queue queue;
- while (t--) {
- string input;
- cin >> input;
- if (input == "put") {
- int q;
- cin >> q;
- queue.put(q);
- } else if (input == "size") {
- cout << queue.Queue_size() << '\n';
- } else {
- queue.get();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement