-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertion.cpp
51 lines (46 loc) · 999 Bytes
/
insertion.cpp
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<iostream>
using namespace std;
class NODE{
public:
int data;
NODE *next;
//constructor
NODE(int value){
data = value;
next = NULL;
}
NODE(){
// Basic Constructor
}
};
int main(){
//dma
// NODE *head;
// head = new NODE(10);
//At Starting - 1) Create the node 2)point temp's next to head 3)head=temp;
// NODE *temp;
// temp = new NODE(20);
// temp->next=head;
// head=temp;
// cout<<head->data;
//ARRAY to LL
NODE *head = NULL;
int arr[5]= {1,2,3,4,5};
for(int i=0;i<5;i++){
if(head == NULL){
head = new NODE(arr[i]);
}
else{
NODE *temp;
temp = new NODE(arr[i]);
temp->next=head;
head=temp;
}
}
//Traversing the LL
NODE *temp = head;
while(temp != NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
}