Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class List
- {
- private:
- struct Node
- {
- int value;
- Node* prev;
- Node* next;
- };
- Node* first;
- Node* last;
- int indicator;
- public:
- List()
- {
- first = NULL;
- last = NULL;
- indicator = 0;
- }
- void OneShot(int v)
- {
- Node* temp = new Node;
- temp->value = v;
- cout << temp->value <<'\n';
- temp->prev = last;
- if ( (temp->value < 0)&(indicator == 0) )
- {
- delete temp;
- ++indicator;
- }
- else
- {
- if(last)
- {
- last->next = temp;
- last = temp;
- temp->next = NULL;
- }
- else
- {
- first = temp;
- temp->next = NULL;
- last = temp;
- }
- }
- }
- void print()
- {
- Node* temp = first;
- while( temp != NULL )
- {
- cout << temp->value << '\n';
- temp = temp->next;
- }
- }
- ~List()
- {
- Node* temp = first;
- while (first != NULL)
- {
- temp = first;
- first = first->next;
- delete temp;
- }
- }
- };
- int main()
- {
- List l;
- cout << "List:"<<'\n';
- l.OneShot(1);
- l.OneShot(2);
- l.OneShot(-3);
- l.OneShot(4);
- l.OneShot(-5);
- l.OneShot(6);
- cout << "New List:"<<'\n';
- l.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement