Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // ConsoleApplication8.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. using namespace std;
  7. struct Node {
  8. int data;
  9. Node *next;
  10. };
  11. struct Queue{
  12. int size;
  13. Node* first;
  14. Node* last;
  15. };
  16. void Creation(Queue*Q) {
  17. Q->first = new Node; // выдялем память под новый элемент:
  18. Q->first->next = NULL;
  19. Q->last = Q->first;
  20. Q->size = 0;
  21. }
  22. void Add(Queue*Q) {
  23. int value;
  24. cout << "Value";
  25. cin >> value;
  26. Q->last->next = new Node;
  27. Q->last = Q->last->next;
  28. Q->last->data = value;
  29. Q->last->next = NULL; // обнуление указателя на след.элемент
  30. Q->size++;
  31. }
  32. int top(Queue *Q) {
  33. return Q->last->next->data;
  34. }
  35. bool Full(Queue*Q) {
  36. if (Q->first == Q->last) return true;
  37. else return false;
  38. }
  39. int main() {
  40. Queue Q;
  41. Creation(&Q);
  42. for (int i = 0; i < 5; i++) {
  43. Add(&Q);
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement