Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node
- {
- public:
- int data = NULL;
- Node* next = nullptr;
- Node* prev = nullptr;
- Node() = default;
- Node(int data)
- : data(data)
- {
- }
- };
- class Babajua
- {
- public:
- Node* first = nullptr;
- Node* last = nullptr;
- ~Babajua()
- {
- Node* i_next;
- for (Node* i = first; i != nullptr; i)
- {
- i_next = i->next;
- delete i;
- i = i_next;
- }
- first = nullptr;
- }
- int operator [](int index)
- {
- Node* c = this->first;
- int size = 0;
- while (c)
- {
- c = c->next;
- size++;
- }
- while (index >= size)
- index -= size;
- c = this->first;
- for (int i = 0; i < index; i++)
- {
- c = c->next;
- }
- return c->data;
- }
- void push_back(int data)
- {
- if (not this->first)
- {
- this->first = this->last = new Node(data);
- return;
- }
- Node* previously_last = this->last;
- this->last = new Node(data);
- previously_last->next = this->last;
- }
- /*friend ostream& operator << (ostream& output, Babajua& object)
- {
- return output << object.first->data;
- }*/
- };
- ostream& operator << (ostream& output, Babajua& object)
- {
- return output << object.first->data;
- }
- int main()
- {
- Babajua a;
- a.first = new Node(6);
- a.first->next = new Node(256);
- a.first->next->next = new Node(95);
- cout << a[10000000] << endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment