NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
c_list.cpp
1#include <game/cLib/c_list.hpp>
2#include <types.h>
3
5
6 // If no previous node is given, prepend the new node
7 if (prevNode == nullptr)
8 return prepend(node);
9
10 if (node != nullptr) {
11 node->mpNext = prevNode->mpNext;
12 node->mpPrev = prevNode;
13 prevNode->mpNext = node;
14
15 // If the node has a successor, link it as well
16 // Else set the new node as last
17 if (node->mpNext != nullptr) {
18 node->mpNext->mpPrev = node;
19 } else {
20 mpLast = node;
21 }
22
23 } else {
24 return false;
25 }
26
27 return true;
28}
29
31 if (node != nullptr) {
32
33 // If the node has a predecessor, update it
34 // Else set the next node as the first node
35 if (node->mpPrev != nullptr) {
36 node->mpPrev->mpNext = node->mpNext;
37 } else if (node == mpFirst) {
38 mpFirst = node->mpNext;
39 }
40
41 // If the node has a successor, update it
42 // Else set the previous node as the last node
43 if (node->mpNext != nullptr) {
44 node->mpNext->mpPrev = node->mpPrev;
45 } else if (node == mpLast) {
46 mpLast = node->mpPrev;
47 }
48
49 // Clean the fields
50 node->mpPrev = nullptr;
51 node->mpNext = nullptr;
52
53 } else {
54 return false;
55 }
56
57 return true;
58}
59
61 if (node != nullptr) {
62
63 // If the last node exists, update it
64 // Else set the new node as the first one as well
65 if (mpLast != nullptr) {
66 mpLast->mpNext = node;
67 node->mpPrev = mpLast;
68 } else {
69 mpFirst = node;
70 }
71 mpLast = node;
72
73 } else {
74 return false;
75 }
76
77 return true;
78}
79
81 if (node != nullptr) {
82
83 // If the first node exists, update it
84 // Else set the new node as the last one as well
85 if (mpFirst != nullptr) {
86 mpFirst->mpPrev = node;
87 node->mpNext = mpFirst;
88 } else {
89 mpLast = node;
90 }
91 mpFirst = node;
92
93 } else {
94 return false;
95 }
96
97 return true;
98}
bool append(cListNd_c *node)
Adds a node to the end of the list.
Definition c_list.cpp:60
bool remove(cListNd_c *node)
Removes a node from the list.
Definition c_list.cpp:30
cListNd_c * mpFirst
The first node in the list.
Definition c_list.hpp:67
cListNd_c * mpLast
The last node in the list.
Definition c_list.hpp:68
bool prepend(cListNd_c *node)
Adds a node to the beginning of the list.
Definition c_list.cpp:80
bool insertAfter(cListNd_c *node, cListNd_c *prevNode)
Inserts a node after the given previous node.
Definition c_list.cpp:4
A doubly-linked list node. See cListMg_c.
Definition c_list.hpp:7
cListNd_c * mpNext
The next node.
Definition c_list.hpp:17
cListNd_c * mpPrev
The previous node.
Definition c_list.hpp:16