-
Notifications
You must be signed in to change notification settings - Fork 0
/
Double_List.h
44 lines (37 loc) · 884 Bytes
/
Double_List.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
struct Node {
int data;
Node* next;
Node* prev;
Node(int data, Node* next,Node* prev) : data{ data }, next{ next }, prev{prev} {}
~Node() { delete prev; delete next; }
};
class Double_List {
//class Node;
Node* head = nullptr;
public:
class Iterator {
Node* p;
public:
explicit Iterator(Node* p) : p{ p } {}
int& operator*() { return p->data; }
Iterator& operator++() {
p = p->next;
return *this;
}
bool operator==(const Iterator& other) const {
return p == other.p;
}
bool operator!=(const Iterator& other) const {
return !(*this == other);
}
};
Iterator end() { return Iterator{ nullptr }; }
Iterator begin() { return Iterator{ head }; }
//List();
~Double_List();
void addToFront(int n);
void reverse_print();
void insert(int data,int pos);
//friend std::ostream& operator<<(std::ostream& out, List& L);
};