Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class List
  6. {
  7. private:
  8. struct Node
  9. {
  10. int value;
  11. Node* prev;
  12. Node* next;
  13. };
  14. Node* first;
  15. Node* last;
  16. int indicator;
  17.  
  18. public:
  19. List()
  20. {
  21. first = NULL;
  22. last = NULL;
  23. indicator = 0;
  24. }
  25.  
  26.  
  27. void OneShot(int v)
  28. {
  29. Node* temp = new Node;
  30. temp->value = v;
  31. cout << temp->value <<'\n';
  32. temp->prev = last;
  33.  
  34. if ( (temp->value < 0)&(indicator == 0) )
  35. {
  36. delete temp;
  37. ++indicator;
  38. }
  39. else
  40. {
  41. if(last)
  42. {
  43. last->next = temp;
  44. last = temp;
  45. temp->next = NULL;
  46. }
  47. else
  48. {
  49. first = temp;
  50. temp->next = NULL;
  51. last = temp;
  52. }
  53. }
  54. }
  55.  
  56. void print()
  57. {
  58. Node* temp = first;
  59. while( temp != NULL )
  60. {
  61. cout << temp->value << '\n';
  62. temp = temp->next;
  63. }
  64. }
  65.  
  66. ~List()
  67. {
  68. Node* temp = first;
  69. while (first != NULL)
  70. {
  71. temp = first;
  72. first = first->next;
  73. delete temp;
  74. }
  75. }
  76. };
  77.  
  78. int main()
  79. {
  80. List l;
  81. cout << "List:"<<'\n';
  82. l.OneShot(1);
  83. l.OneShot(2);
  84. l.OneShot(-3);
  85. l.OneShot(4);
  86. l.OneShot(-5);
  87. l.OneShot(6);
  88. cout << "New List:"<<'\n';
  89. l.print();
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement