-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayToLinkedList.DLL
More file actions
46 lines (40 loc) · 825 Bytes
/
ArrayToLinkedList.DLL
File metadata and controls
46 lines (40 loc) · 825 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>
#include<stdlib.h>
#include<vector>
using namespace std;
struct node {
int data;
node *next;
node *back;
node (int data1) {
data=data1;
next=nullptr;
back=nullptr;
}
node (int data1,node*next1,node*back1) {
data=data1;
next=next1;
back=back1;
}
};
node *convertarr2DLL (vector<int>&arr) {
node *head=new node(arr[0]);
node *prev=head;
for (int i=1;i<arr.size();i++) {
node *temp=new node(arr[i],nullptr,prev);
prev->next=temp;
prev=temp;
}
return head;
}
void printNode(node *head) {
while(head!=nullptr) {
cout<<head->data<<" ";
head=head->next;
}
}
int main() {
vector<int> arr={1,2,3,4,5};
node *head=convertarr2DLL(arr);
printNode(head);
}