-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchElementInLL.SLL
More file actions
48 lines (41 loc) · 862 Bytes
/
SearchElementInLL.SLL
File metadata and controls
48 lines (41 loc) · 862 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
#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;
}
};
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;
}
int SearchElementInLL (node *head,int value) {
node *temp=head;
while (temp) {
if (temp->data==value) {
return 1;
}
temp=temp->next;
}
return 0;
}
int main() {
vector <int> arr= {1,2,3,4,5};
node *head= convertarr2ll(arr);
cout << SearchElementInLL (head,3);
}