-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathembedded_list.cpp
More file actions
53 lines (40 loc) · 1.37 KB
/
embedded_list.cpp
File metadata and controls
53 lines (40 loc) · 1.37 KB
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
#include <iostream>
#include <thread>
#include <chrono>
#include <dsvisual.hpp>
using namespace dsvisual;
using MyNode = dstruct::EListNode<ds::Array<int, 4>>;
int main() {
//PlatformManager::setWindowFPS(60);
PlatformManager::setRecorder();
ds::EmbeddedList<MyNode> eList;
eList.setVisible(true);
eList.setPos(0, 0);
eList.setSize(1920, 1080);
{ // data struct visualization
ds::EmbeddedList<MyNode>::init(eList.headNodePtr());
MyNode *headNodePtr = eList.headNodePtr();
MyNode *midNodePtr = nullptr;
assert(headNodePtr->link.next = headNodePtr->link.prev); // empty test
// tail-insert
auto insertPtr = headNodePtr;
for (int i = 0; i < 2; i++) {
auto currNodePtr = new MyNode();
eList.add(insertPtr, currNodePtr, 200);
insertPtr = currNodePtr;
}
// mid-insert
for (int i = 0; i < 3; i++) {
auto currNodePtr = new MyNode();
eList.add(insertPtr, currNodePtr, 200);
}
// release
while (!ds::EmbeddedList<MyNode>::empty(headNodePtr)) {
auto firstNodePtr = MyNode::to_node(headNodePtr->link.next);
eList.del(headNodePtr, MyNode::to_node(headNodePtr->link.next), 200);
delete firstNodePtr;
}
}
PlatformManager::waitWindowClosed();
return 0;
}