-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneWayLinkedList.h
106 lines (76 loc) · 2.56 KB
/
OneWayLinkedList.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* @Name: One Way Linked List C++
* @Author: Max Base
* @Date: 2022-11-14
* @Repository: https://github.com/basemax/OneWayLinkedListCpp
*/
class Node {
public:
int data; // Data
Node* next; // Pointer to next node
// Node Constructor
Node(int data);
};
class OneWayLinkedList {
private:
Node* head; // Pointer to head node
Node* tail; // Pointer to tail node and Tail is the last node in the list.
int size; // Size of list
public:
// OneWayLinkedList Constructor
OneWayLinkedList();
// Add new node to the beginning of the list
void addBegin(int data);
// Add new node to the end of the list
void addEnd(int data);
// Deep copy
OneWayLinkedList* deepCopy();
// Deep copy nodes
Node* deepCopyNodes();
// Print all nodes
void print();
// Delete all nodes
void deleteAll();
// Support delete operator
// ~OneWayLinkedList();
// Check has a node with a specific data in the list or not
bool has(int data);
// Get the size of the list
int getSize();
// Get the node by searching with data
Node* getNode(int data);
// Check there is a node with a specific data in the list or not
int hasNode(int data);
// Check there is a node with a specific data in the list or not (with a recursive function)
int hasNodeRecursive(int data, Node* node);
// Maloc a new node
Node* mallocNode(int data);
// Delete a node with a specific data
void deleteNode(int data);
// Get the node by searching with index
Node* getNodeByIndex(int index);
// Delete a node after a node with a specific index
void deleteNodeAfterIndex(int index);
// Delete a node before a node with a specific data
void deleteNodeBeforeData(int data);
// Delete a node with a specific index
void deleteNodeByIndex(int index);
// Delete a node after a node with a specific index
void deleteNodeAfterData(int data);
// Delete a node before a node with a specific index
void deleteNodeBeforeIndex(int index);
// Count number of nodes
int count();
// Count number of nodes with a recursive function
int countRecursive(Node* node);
// Get the first node
Node* getFirstNode();
// Get the last node
Node* getLastNode();
// Reverse the list
void reverse();
// Reverse the list with a recursive function
void reverseRecursive(Node* node);
// Get the middle node
Node* getMiddleNode();
};