-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublechained.cpp
44 lines (36 loc) · 1.19 KB
/
doublechained.cpp
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
/**
* Exemplo de utilização de uma lista duplamente encadeada
*/
#include <iostream>
#include <unistd.h>
#include "linkedlist.h"
void seeDualNode(DualStringNode * list) {
if (list != NULL) {
cout << "=============" << endl;
if (list->previous != NULL) {
cout << "content prior to current node" << endl;
cout << list->previous->content << endl;
} else {
cout << "this node has no previous element" << endl;
}
if (list->next != NULL) {
cout << "content after the current node" << endl;
cout << list->next->content << endl;
} else {
cout << "this node has no next element" << endl;
}
cout << "=============" << endl;
usleep(5*1000000);
return seeDualNode(list->next);
}
}
int main(void) {
DualStringNode * nodeOne = new DualStringNode("Node One");
DualStringNode * nodeTwo = new DualStringNode("Node two");
DualStringNode * nodeThree = new DualStringNode("Node Three");
nodeOne->addNext(nodeTwo);
nodeTwo->addPrevious(nodeOne);
nodeTwo->addNext(nodeThree);
nodeThree->addPrevious(nodeTwo);
seeDualNode(nodeOne);
}