Advertisement
irapilguy

ДИКИЙ КОД 2

Nov 1st, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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. cout <<"WHYYY "<<t->data<<"\n";
  50. delete t->prev;
  51. }
  52. }
  53. int main() {
  54. int n;
  55. cin >> n;
  56. for (int i = 0; i < n; i++) {
  57. int x;
  58. cin >> x;
  59. push(x);
  60. }
  61. int del;
  62. cin >> del;
  63. for (int j = 0; j < del; j++) {
  64. int bred = pop();
  65. cout << bred << "\n\n";
  66. }
  67. cout << front() << "\n\n";
  68. clear(start);
  69. cout << size(start) << "\n";
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement