Skip to content

Commit 6153e03

Browse files
first commit
0 parents  commit 6153e03

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

BinarySearch.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//------------------- Binary Search ------------------
2+
#include<iostream>
3+
using namespace std;
4+
5+
int main()
6+
{
7+
// Location: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
8+
int data[20] = {10, 15, 18, 25, 30, 33, 40,45,50,55,60,64,66,68,69,70,75,78};
9+
int item, first, last, mid, lb = 0, ub = 18;
10+
11+
first = lb, last = ub;
12+
mid = (first + last) / 2;
13+
14+
cout<<"Enter the Item Value = ";
15+
cin>>item;
16+
17+
while((data[mid] != item) && (first <= last))
18+
{
19+
if(item < data[mid])
20+
last = mid - 1;
21+
22+
else
23+
first = mid + 1;
24+
25+
mid = (first + last) / 2;
26+
}
27+
28+
if(data[mid] == item)
29+
cout<<"Item Found and Location is = "<<mid+1;
30+
31+
else
32+
cout<<"Item not Found\n";
33+
34+
return 0;
35+
}

BinarySearch.exe

56.1 KB
Binary file not shown.

BinarySearch.o

2.64 KB
Binary file not shown.

Selection sort 001.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//-----------Selection Sort------------
2+
#include<iostream>
3+
using namespace std;
4+
5+
int main ()
6+
{
7+
int a[] = {9,13,15,11,10};
8+
int i,j,min_index,temp;
9+
10+
for(i=0;i<5;i++)
11+
{
12+
min_index = i;
13+
14+
for(j=i+1;j<5;j++)//Inner loop
15+
{
16+
if(a[j]<a[min_index])
17+
{
18+
min_index = j;
19+
}
20+
}
21+
if( min_index != 5)
22+
{
23+
temp = a[i];
24+
a[i] = a[min_index];
25+
a[min_index] = temp;
26+
}
27+
cout<<" "<<a[i];
28+
}
29+
30+
31+
32+
return 0;
33+
}

Selection sort 001.exe

55.6 KB
Binary file not shown.

Selection sort 001.o

2.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)