blob: 8fbf2b221f55923cf13324e3cc2f815cee8440a4 (
plain) (
blame)
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
|
#ifndef SINGLY_LINKED_LIST_HPP
#define SINGLY_LINKED_LIST_HPP
struct ListNode {
int _data = 0;
ListNode* _next = nullptr;
};
struct SinglyLinkedList {
size_t _size;
ListNode* _head = nullptr;
};
//SinglyLinkedList singlylinkedlist{};
//ListNode listnode{};
//
//listnode._data = 1;
//singlylinkedlist._head = &listnode;
bool Append(SinglyLinkedList* list, ListNode* node) {
//if empty
if (list->_size == 0)
{
list->_head = node;
list->_size++;
return true;
}
//if not empty
ListNode* travel = nullptr;
for (travel = list->_head; travel->_next != nullptr;)
{
travel = travel->_next;
}
travel->_next = node;
return true;
}
#endif
|