GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Search-Array/main.cpp at master · sanjayholla/Search-Array

Expand file tree

/

main.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
58 lines (50 loc) · 1.3 KB
/

main.cpp

Copy path

File metadata and controls

58 lines (50 loc) · 1.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
54
55
56
57
58
//To sort the array and search for a fiven element in the array
#include <cstdlib>
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int array[50],size,temp,element,i,mid;
cout<<"Enter the number of elements:";
cin>>size;
cout<<"Enter the elements:";
for(i=0;i<size;i++){
cin>>array[i];
}
for(i=0;i<size;i++){ //bubble sort
for(int j=0;j<size-i-1;j++){
if(array[j]>array[j+1]){
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
cout<<"The sorted array is:";
for(i=0;i<size;i++)
cout<<array[i]<<" ";
char ch='y';
cout<<"Enter the element to search for:";
cin>>element;
int beg=0,last=size-1;
int flag=0;
while(beg<=last){ //binary search
mid=(beg+last)/2;
if(array[mid]==element)
{
flag=1;
break;
}
else if(array[mid]<element)
beg=mid+1;
else if(array[mid]>element)
last=mid-1;
}
if(flag==0)
cout<<"Element not found";
else
cout<<"Element found!";
getche();
return 0;
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.