#include
#include
#include
using namespace std;
void write(int a[],int n) //funkcija za ispis polja
{ for(int i=0;i
cout<
void exchange(int &a,int &b)
{
int t=a;
a=b;
b=t;
}//definicija za sortiranje
void bubbleSort(int a[],int l,int r)
{ int h;
int elem;
int j;
int i;
for (h =1;h<(r-1)/9;h=3*h + 1);
while (h>0)
{ for(i=l+h;i<=r;i++)
{ j=i;
elem = a[i];
while( j>=l+h && elem < a[j-h])
{ a[j] = a[j-h];
j = j-h;
}
a[j] = elem;
}
h=h/3; //h/=3;
}
cout<
int pretrazivanje(int a[],int n,int target)
{ int mid, beg=0, end=n-1;
while(beg<=end)
{ mid=((beg+end)/2);
if(target>a[mid])
{
beg=mid+1;
}
else if(target
{
end=mid-1;
}
else
{
beg=end+1;
}
}
if(target==a[mid])
{ return mid;
} else
{ return -1;
} }
int main()
{ int n,a[100];
do
{ cout<<"Unesite broj elemenata: ";
cin>>n;
}
while(n>100);
srand(static_cast
for(int i=0;i
}
write(a,n);
cout<
bubbleSort(a,0,n-1);
cout<
int mid;
int target;
int d;
cout<<"koji broj trazis?";
cin>>target;
d=pretrazivanje(a,n,target);
cout<<"index trazenog elementa je"<
}
Post je objavljen 24.04.2013. u 01:03 sati.