-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionAtHead.SLL
More file actions
46 lines (41 loc) · 891 Bytes
/
Copy pathInsertionAtHead.SLL
File metadata and controls
46 lines (41 loc) · 891 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 <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
struct node {
int data;
node *next;
node (int data1, node *next1) {
data=data1;
next=next1;
}
node (int data1) {
data=data1;
next=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 *mover=head;
for (int i=1;i<arr.size();i++) {
node *temp=new node (arr[i]);
mover->next=temp;
mover=mover->next;
}
return head;
}
node *InsertionAtHead (node *head, int value) {
return new node (value,head);
}
int main () {
vector <int> arr = {1,2,3,4,5};
node *head = convertarr2LL(arr);
head= InsertionAtHead (head,0);
printNodes(head);
}