Advertisement
irapilguy

ДИКИЙ КОД

Nov 1st, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4. struct Queue {
  5. int data;
  6. Queue *prev;
  7. };
  8. Queue *start = NULL;
  9. Queue *last = NULL;
  10.  
  11. Queue * createNewElement(int x) {
  12. Queue *t = new Queue();
  13. t->data = x;
  14. t->prev = NULL;
  15. return t;
  16. }
  17. void push(int x) {
  18. if (start == NULL) {
  19. Queue * t = createNewElement(x);
  20. start = t;
  21. last = t;
  22. return;
  23. }
  24. Queue *t = createNewElement(x);
  25. last->prev = t;
  26. last = t;
  27. }
  28. int pop() {
  29. if (start == NULL) return 0;
  30. int res = start->data;
  31. start = start->prev ;
  32. return res;
  33. }
  34. int front() {
  35. if (start != NULL) return start->data;
  36. }
  37. int countt = 0;
  38. int size(Queue * p) {
  39. if (p == NULL) return 0;
  40. if (p->prev != NULL) {
  41. countt++;
  42. size(p->prev);
  43. }
  44. return countt + 1;
  45. }
  46. void clear(Queue *t) {
  47. if (t!= NULL) {
  48. clear(t->prev);
  49. delete t;
  50. }
  51. }
  52. int main() {
  53. int n;
  54. cin >> n;
  55. for (int i = 0; i < n; i++) {
  56. int x;
  57. cin >> x;
  58. push(x);
  59. }
  60. int del;
  61. cin >> del;
  62. for (int j = 0; j < del; j++) {
  63. int bred = pop();
  64. cout << bred << "\n\n";
  65. }
  66. cout << front() << "\n\n";
  67. clear(start);
  68. cout << size(start) << "\n";
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement