You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//.......................................This program is used to define Link least using structure.........................................................
1
2
#include<iostream>
2
3
usingnamespacestd;
4
+
5
+
//.......................node is user define datatype , which contain two elements in it....................................
6
+
// 1) integer data (its own data)
7
+
// 2) node type pointer, used to store address of next node
3
8
structnode{
4
9
int data;
5
10
node *next;
6
11
};
7
-
voidprintList(node *n){
8
-
while(n!=NULL){
12
+
13
+
// printList() function is used to print data stores in all nodes
14
+
voidprintList(node *n)
15
+
{
16
+
while(n!=NULL){
9
17
cout<<n->data<<endl;
10
18
n=n->next;
11
19
12
20
}
13
21
}
14
22
15
23
intmain(){
24
+
25
+
// defining three pointers of type node, use to point elements of node
16
26
node *head=newnode();
17
27
node *second=newnode();
18
28
node *third=newnode();
29
+
19
30
head->data=5;
31
+
// next pointer of head node stores addresscof second node
20
32
head->next=second;
21
33
22
34
second->data=9;
35
+
// next pointer of second node stores address of third node
23
36
second->next=third;
24
37
25
38
third->data=7;
39
+
// next pointer of third node stores NULL value in it, because there is no next node
26
40
third->next=NULL;
27
-
41
+
42
+
// calling to print data of all nodes, using only head node
0 commit comments