-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5_Q3.cpp
More file actions
50 lines (50 loc) · 918 Bytes
/
Lab5_Q3.cpp
File metadata and controls
50 lines (50 loc) · 918 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
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node*next;
Node(int d){
data=d;
next=NULL;
}
};
void insertatail(Node*&head,Node*&tail,int val){
Node*temp=new Node(val);
if(head==NULL){
head=temp;
tail=temp;
}else{
tail->next=temp;
tail=temp;
}
}
bool searchnumber(Node*head,int target){
if(head==NULL){
return false;
}
bool number_present=searchnumber(head->next,target);
if(head->data==target){
return true;
}
return number_present;
}
int main(){
Node*head=NULL;
Node*tail=NULL;
insertatail(head,tail,1);
insertatail(head,tail,9);
insertatail(head,tail,1);
insertatail(head,tail,2);
insertatail(head,tail,5);
insertatail(head,tail,4);
insertatail(head,tail,3);
int num;
cout<<"enter number to search"<<endl;
cin>>num;
if(searchnumber(head,num)){
cout<<"Number "<<num<< " found"<<endl;
}else{
cout<<"Number "<<num<<" not found"<<endl;
}
}