#include <cstdlib>
#include <iostream>
using namespace std;
void MinMaks2(int A[], int i, int j, int &min, int &maks)
{
int min1, min2, maks1, maks2, k;
if (i=j)
{
min = A[i];
maks = A[i];
}
else
{
if (i = j-1)
{
if (A[i] < A[j])
{
maks = A[j];
min = A[i];
}
else
{
maks = A[i];
min = A[j];
}
}
else
{
k = ((i+j)/2);
MinMaks2(A, i, k, min1, maks1);
MinMaks2(A, i+1, j, min2, maks2);
}
if (min1 < min2)
{
min = min1;
}
else
{
min = min2;
}
}
if (maks1 < maks2)
{
maks = maks2;
}
else
{
maks = maks1;
}
}
int main(int argc, char *argv[])
{
int A[] = {3,6,1,10,8,19,2,4};
int i = 0;
int j = 7;
int min, maks;
MinMaks2(A, i, j, min, maks);
cout<<"min = "<<min<<endl;
cout<<"maks = "<<maks<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
void MinMaks2(int A[], int i, int j, int &min, int &maks)
{
int min1, min2, maks1, maks2, k;
if (i=j)
{
min = A[i];
maks = A[i];
}
else
{
if (i = j-1)
{
if (A[i] < A[j])
{
maks = A[j];
min = A[i];
}
else
{
maks = A[i];
min = A[j];
}
}
else
{
k = ((i+j)/2);
MinMaks2(A, i, k, min1, maks1);
MinMaks2(A, i+1, j, min2, maks2);
}
if (min1 < min2)
{
min = min1;
}
else
{
min = min2;
}
}
if (maks1 < maks2)
{
maks = maks2;
}
else
{
maks = maks1;
}
}
int main(int argc, char *argv[])
{
int A[] = {3,6,1,10,8,19,2,4};
int i = 0;
int j = 7;
int min, maks;
MinMaks2(A, i, j, min, maks);
cout<<"min = "<<min<<endl;
cout<<"maks = "<<maks<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
No comments:
Post a Comment