-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked list2.cpp
More file actions
50 lines (41 loc) · 753 Bytes
/
Copy pathlinked list2.cpp
File metadata and controls
50 lines (41 loc) · 753 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
#include<stdio.h>
#include<stdlib.h>
//1
typedef struct node{
int value;
struct node *next;
}node;
int main(){
int length,i;
//2
printf("Enter size of the list : ");
scanf("%d",&length);
//3
struct node *headNode, *currentNode, *temp;
//4
for(i=0 ; i<length; i++){ //5
currentNode = (node *)malloc(sizeof(node)); //6
printf("Enter element %d : ",(i+1));
scanf("%d", ¤tNode->value);
//7
if(i==0){
headNode = temp = currentNode;
}else{
//8
temp->next = currentNode;
temp = currentNode;
}
}
//9
temp->next = NULL;
+
//10
temp = headNode;
//11
printf("Iterating through the elements of the linked list : \n");
while(temp != NULL){
//12
printf("%d \n",temp->value);
temp = temp -> next;
}
}