-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionAtHead.DLL
More file actions
53 lines (46 loc) · 1021 Bytes
/
Copy pathInsertionAtHead.DLL
File metadata and controls
53 lines (46 loc) · 1021 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
51
52
53
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
struct node {
int data;
node *next;
node *back;
node (int data1, node *next1,node* back1) {
data=data1;
next=next1;
back=back1;
}
node (int data1) {
data=data1;
next=nullptr;
back=nullptr;
}
};
void printNodes(node *head) {
while (head!=NULL) {
cout << head->data << endl;
head=head->next;
}
}
node *convertarr2LL (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;
}
node *InsertionAtHead (node *head, int value) {
node *newnode= new node (value,head,NULL);
head->back=newnode;
return newnode;
}
int main () {
vector <int> arr = {1,2,3,4,5};
node *head = convertarr2LL(arr);
head= InsertionAtHead(head,0);
printNodes(head);
}