-
Notifications
You must be signed in to change notification settings - Fork 0
/
searching2.java
53 lines (46 loc) · 1.11 KB
/
searching2.java
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
//searching an element in the linked list by recursive approach
class Node
{
int data;
Node next;
Node(int d)
{
data=d;
next=null;
}
}
public class Itersearch
{
Node head;
public void insert(int element)
{
Node n = new Node(element);
n.next=head;
head=n;
}
public boolean search(Node head, int item)
{
if(head==null)
return false;
if(head.data==item)
{
return true;
}
return(search(head.next, item));
}
public static void main(String args[])
{
Itersearch is = new Itersearch();
is.insert(98);
is.insert(54);
is.insert(46);
is.insert(64);
is.insert(74);
is.insert(63);
is.insert(9);
// BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
// System.out.println("Enter the element u wanna search!");
// int num = Integer.parseInt(br.readLine());
System.out.println("Data present = "+ is.search(is.head, 64));
}
}