-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayToLL.cpp
More file actions
40 lines (38 loc) · 754 Bytes
/
arrayToLL.cpp
File metadata and controls
40 lines (38 loc) · 754 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
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node* next;
public:
Node(int data1,Node* next1){
data=data1;
next=next1;
}
Node(int data1){
data=data1;
next=nullptr;
}
};
Node* convert2LL(vector<int> &arr){
Node* head=new Node(arr[0]);
Node* mover=head;
for(int i=1;i<arr.size();i++){
Node* temp=new Node(arr[i]);
mover->next=temp;
mover=temp;
}
return head;
}
int main(){
vector<int> arr={1,2,3,4,5,6};
Node* head=convert2LL(arr);
// cout<<head->data;
// traversal a linkde list
Node* temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
return 0;
}