#include<stdio.h>
#include<pthread.h>
struct minmax
{
int min;
int max;
};
typedef struct minmax s;
int a[10],n;
void *min_max();
s *smain,*sthread;
main()
{
int finalmin,finalmax,i;
pthread_t tid;
smain=(s*)malloc(sizeof(s));
printf("Enter the limit : ");
scanf("%d",&n);
printf("\nEnter the elemenats :");
for(i=0;i<n;i++)
{
printf("\na[%d] : ",i);
scanf("%d",&a[i]);
}
smain->min=smain->max=a[0];
pthread_create(&tid,NULL,min_max,NULL);
for(i=0;i<n/2;i++)
{
if(a[i] < smain->min)
smain->min=a[i];
if(a[i] > smain->max)
smain->max=a[i];
}
pthread_join(tid,NULL);
if(smain->min <= sthread->min)
finalmin=smain->min;
else
finalmin=sthread->min;
if(smain->max >= sthread->max)
finalmax=smain->max;
else
finalmax=sthread->max;
printf("\nMin : %d \n Max : %d",finalmin,finalmax);
}
void *min_max()
{
int i;
sthread=(s*)malloc(sizeof(s));
sthread->min=sthread->max=a[n/2];
for(i=a[n/2];i<n;i++)
{
if(a[i] < sthread->min)
sthread->min=a[i];
if(a[i] > sthread->max)
sthread->max=a[i];
}
}