Guest User

Queue

a guest
Apr 11th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Сама очередь.
  2.  
  3. class queue
  4. {
  5. private:
  6. struct queue_ob
  7. {
  8. char value;
  9. queue_ob addr;
  10. };
  11. queue_ob head;
  12. queue_ob tail;
  13.  
  14. public:
  15. int size;
  16. queue(char x)
  17. {
  18. head = new(queue_ob);
  19. tail = head;
  20. head->value = x;
  21. head->addr = 0;
  22. size = 1;
  23. }
  24.  
  25. char get_value()
  26. {
  27. return head->value;
  28. }
  29.  
  30. int stack_size()
  31. {
  32. return size;
  33. }
  34.  
  35. void push(char value)
  36. {
  37. size++;
  38. queue_ob temp = new(queue_ob);
  39. temp->addr = 0;
  40. temp->value = value;
  41. tail->addr = temp;
  42. tail = temp;
  43. }
  44. /поправить выдачу из очереди/
  45. void pop(char ret)
  46. {
  47. if (size == 0)
  48. {
  49. cout << "Очередь пуста - удалять нечего!" << endl;
  50. return;
  51. }
  52. queue_ob temp = head;
  53. ret = head->value;
  54. head = head->addr;
  55. delete temp;
  56. size--;
  57. }
  58.  
  59. void peek(char ret)
  60. {
  61. if (size == 0)
  62. {
  63. cout << "Очередь пуста!" << endl;
  64. return;
  65. }
  66. ret = head->value;
  67. }
  68. };
  69.  
  70. Забивание данных и выдача
  71.  
  72. string line_01;
  73. char line[50];
  74. ifstream read_line_01("текстовик с данными");
  75. getline(read_line_01, line_01);
  76. char first_line = &line_01[0];
  77.  
  78.  
  79. char char_line = &line_01[1];
  80. char current_value;
  81. while (getline(read_line_01, line_01))
  82. {
  83. char_line = &line_01[0];
  84. ob.push(char_line);
  85. }
  86.  
  87. while (ob.size > 1)
  88. {
  89. ob.pop(&current_value);
  90. str_sep(current_value);
  91. }
  92. read_line_01.close();
Advertisement
Add Comment
Please, Sign In to add comment