-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkdlist.cpp
More file actions
53 lines (39 loc) · 933 Bytes
/
Copy pathLinkdlist.cpp
File metadata and controls
53 lines (39 loc) · 933 Bytes
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
// head stores only next node ptr addr eorking v1
// node contains elements and ptr addr the ptr addr holds addr of next node and last node have nulptr
#include <iostream>
using namespace std;
class node
{
public:
int element;
node* next;
// node()
// {
// head = nullptr;
// }
};
int main()
{
node n1;
node n2;
node* head;
node* temp = head;
head = &n1;
n1.element = 33;
n1.next = nullptr;
n2.element = 44;
n2.next = nullptr;
n1.next = &n2;
cout << n1.element << endl ;
cout << n1.next << endl ;
cout << n1.next->element << endl ;//using address of next get element
cout << n2.element << endl ;
cout << n2.next << endl ;
cout << head->element << endl ;
cout << head->next->element << endl ;
while(temp != nullptr)
{
cout << temp->element << endl ;
temp = temp->next ;
}
}