-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlec1_3.cpp
More file actions
46 lines (42 loc) · 715 Bytes
/
Copy pathlec1_3.cpp
File metadata and controls
46 lines (42 loc) · 715 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
#include<iostream>
using namespace std;
// insertion at the end
class Node
{
public:
int data;
Node *next;
Node(int value)
{
data = value;
next = NULL;
}
};
int main()
{
Node *Head = NULL;
Node *Tail = NULL;
int arr[] = {2 , 4 , 6 , 8 , 10};
//insert the value at end
for(int i = 0 ;i<5;i++){
// Linked list is empty
if(Head = NULL)
{
Head = new Node(4);
Tail = Head;
}
// Linked list exists
else{
Tail->next = new Node(arr[i]);
Tail = Tail->next;
}
}
Node *temp;
temp = Head;
while(temp)
{
cout<<temp->data<<" ";
temp = temp->next;
}
return 0;
}