link.cpp
1.26 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
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
#include <iostream>
using namespace std;
class Link
{
public:
Link* next;
virtual void Print() = 0;
};
class Displayed : public Link
{
string name;
public:
Displayed(string n): name(n) {};
void Print() override { cout << name << endl; }
;
};
class Task : public Link
{
string name;
public:
Task(string n): name(n) {};
void Print() override { cout << name << endl; }
;
};
class Satellite: public Task, public Displayed
{
public:
Satellite(string n): Task("Task:" + n), Displayed("Displayed:" + n) {};
void Print() override { Task::Print(); Displayed::Print();};
};
Link* insert(Link* list, Link* node)
{
node->next = list;
return node;
}
int main()
{
Link* displayedList = NULL;
displayedList = insert(displayedList, new Displayed("a"));
displayedList = insert(displayedList, new Displayed("b"));
Satellite* s = new Satellite("e");
Displayed* sd = s;
displayedList = insert(displayedList, sd);
Link* taskList = NULL;
taskList = insert(taskList, new Task("c"));
taskList = insert(taskList, new Task("d"));
Task* st = s;
taskList = insert(taskList, st);
Link* iterator = displayedList;
while(iterator)
{
iterator->Print();
iterator=iterator->next;
}
iterator = taskList;
while(iterator)
{
iterator->Print();
iterator=iterator->next;
}
}