-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.h
53 lines (47 loc) · 1001 Bytes
/
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
42
43
44
45
46
47
48
49
50
51
#ifndef LIST_H
#define LIST_H
#include <iostream>
struct Node {
int data;
Node* next;
Node(int data, Node* next) : data{ data }, next{ next } {}
~Node() { delete next; }
};
class List {
//class Node;
protected:
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();
~List();
void addToFront(int n);
int at(int i);
void insert(int, int);
void delete_node(int);
void reverse();
void reverse_r();
void reverse_print();
void print();
void insert_at_end(int);
void delete_at_end();
//friend std::ostream& operator<<(std::ostream& out, List& L);
};
#endif