forked from Anson-Sun/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
112 lines (88 loc) · 1.45 KB
/
template.cpp
File metadata and controls
112 lines (88 loc) · 1.45 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
using namespace std;
char addone(char x)
{
cout << "char: ";
return (x+1);
}
int addone(int x)
{
cout << "int: ";
return (x+1);
}
float addone(float x)
{
cout << "float: ";
return (x+1);
}
double addone(double x)
{
cout << "double: ";
return (x+1);
}
int main()
{
char x1='a';
int x2=1;
float x3=1.1;
double x4=1.11;
cout << addone(x1) << endl;
cout << addone(x2) << endl;
cout << addone(x3) << endl;
cout << addone(x4) << endl;
return 0;
}
***
#include <iostream>
using namespace std;
template <class T>
class node
{
T value;
node *prev,*next;
public:
node()
{
prev=NULL;
next=NULL;
}
void set_value(T value)
{
this->value=value;
}
T get_value()
{
return value;
}
node * get_prev()
{
return prev;
}
node * get_next()
{
return next;
}
void append(node *p)
{
p->prev=this;
if(next!=NULL) next->prev=p;
p->next=next;
next=p;
}
};
int main( )
{
node<float> *ptr;
node<float> node1,node2,node3;
node1.set_value(97.5);
node2.set_value(98.5);
node3.set_value(99.5);
node1.append(&node2);
node2.append(&node3);
for(ptr=&node1 ; ; ptr=ptr->get_next())
{
cout << ptr->get_value() << endl;
if(ptr->get_next()==NULL) break;
}
return 0;
}