Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- struct Queue {
- int data;
- Queue *prev;
- };
- Queue *start = NULL;
- Queue *last = NULL;
- Queue * createNewElement(int x) {
- Queue *t = new Queue();
- t->data = x;
- t->prev = NULL;
- return t;
- }
- void push(int x) {
- if (start == NULL) {
- Queue * t = createNewElement(x);
- start = t;
- last = t;
- return;
- }
- Queue *t = createNewElement(x);
- last->prev = t;
- last = t;
- }
- int pop() {
- if (start == NULL) return 0;
- int res = start->data;
- start = start->prev ;
- return res;
- }
- int front() {
- if (start != NULL) return start->data;
- }
- int countt = 0;
- int size(Queue * p) {
- if (p == NULL) return 0;
- if (p->prev != NULL) {
- countt++;
- size(p->prev);
- }
- return countt + 1;
- }
- void clear(Queue *t) {
- if (t!= NULL) {
- clear(t->prev);
- delete t;
- }
- }
- int main() {
- int n;
- cin >> n;
- for (int i = 0; i < n; i++) {
- int x;
- cin >> x;
- push(x);
- }
- int del;
- cin >> del;
- for (int j = 0; j < del; j++) {
- int bred = pop();
- cout << bred << "\n\n";
- }
- cout << front() << "\n\n";
- clear(start);
- cout << size(start) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement