kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Wednesday, January 28, 2015


thuật toán tìm kiếm tuyến tính cải tiến trên dãy đã sắp xếp
#include<iostream>
using namespace std;
int tim(int *a,int n,int x)
{
int i=0;
while(a[i]!=x && i<n) i++;
if(i==n) return 0;
return i;
}
int tim1(int *a,int n,int x)
{
int i=0;
a[n]=x;
while(a[i]!=x) i++;
if(i==n) return 0;
return i;

}
int tim2caitien(int *a,int n,int x)
{
int i=0;
a[n]=x;
while(a[i]<x) i++;
if(i<n && a[i]==x) return i;
return 0;
}
void main()
{
int a[11]={1,3,6,7,10,11,13,24,45,46},x;
cout<<"tim so x=";
cin>>x;
if(int t=tim2caitien(a,10,x)) cout<<"tim thay tai vi tri: "<<t<<"\n";
else cout<<"khong tim thay";

}

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts