-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeExample.cpp
More file actions
51 lines (43 loc) · 1.08 KB
/
NodeExample.cpp
File metadata and controls
51 lines (43 loc) · 1.08 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
#include <cstdlib>
#include <iostream>
using namespace std;
class node{
private:
int _value;
node *_next;
public:
node(int value=10){_value=value;_next=0;}
int getV(){return _value;}
void add(int i){
if(_next !=0 ){_next=new node(i);}
else{
node *n = this;
while(n->_next!=0){
n = n->_next;
}
n->_next = new node(i);
}
}
int len(){
int s=1;
node *n = _next;
while(n!=0){
s++;
n = _next->_next;
}
}
};
int main(int argc, char *argv[])
{
node n1 = node(10);
cout<<endl<<n1.getV()<<endl;
node n2 = node(-10);
cout<<endl<<n2.getV()<<endl;
n1.add(20);
n1.add(120);
n1.add(220);
n1.add(320);
cout<<endl<<n1.len()<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}