Part A: Multi-threading; inheritance and Interface Polymorphism Provide two impl
ID: 3775092 • Letter: P
Question
Part A: Multi-threading; inheritance and Interface Polymorphism Provide two implementations of Multi-threading, (one uses inheritance and the other uses Interface) for the following tasks: (use synchronized blocks to prevent mutual exclusion violation) i) concurrently find and calculate the highest number in an integer array called myNumbers. i) Update the value to a variable called highestNumber. Part B: Stacks and Queues, Linked-List versus Growable Arrays interface Queuet void Enqueue (int n); int Dequeue0: int length0; interface Stack( void Push int n); int Pop(); int length0; Given the following interfaces for Stacks and Queues, implement each interface in two ways: using a Linked-List and a Stack. (That means, a total of FOUR implementations is needed. E g., Queue using Linked-List & Queue using Growable Array. Provide a short paragraph of your observation once you have completed all the implementation. Use the following class names MyStack1, MyStack2, MyQueuel, MyQueue2 in your code. Part C: Generics Briefly describe which part of code change is needed so that your implementations in Part B can accommodate any type of objects. Meaning: It can store any type of objects. Provide at least two lines of code that shows how the container gets instantiated and how an object can be stored inside your container.Explanation / Answer
{
int Maximum;
int Minimum;
};
int array[arraySize];
void *thread_search_min_max(void *);
int main()
{
pthread_t tid;
struct MaxMin *st_main,*st_th;
int totalMaximum,totalMinimum;
st_main=(struct MaxMin*)malloc(sizeof(struct MaxMin));
int Count;
for(Count=0;Count<arraySize;Count++)
{
printf("Please enter the value of array[%d] :",Count);
scanf("%d",&array[Count]);
}
pthread_create(&tid,NULL,thread_search_min_max,NULL);
st_main->Maximum=array[0];
st_main->Minimum=array[0];
for(Count=1;Count<arrSize/2;Count++)
{
if(array[iCount] > st_main->Maximum)
{
st_main->Maximum=array[Count];
}
if(array[Count] < st_main->Minimum)
{
st_main->Minimum=array[Count];
}
}
pthread_join(tid,(void**)&st_th);
if(st_main->Maximum >= st_th->Maximum)
{
toalMaximum=st_main->Maximum;
}
else
{
totalMaximum=st_th->Maximum;
}
if(st_main->Minimum <=st_th->Minimum)
{
toalMinimum=st_main->Minimum;
}
else
{
totalMinimum=st_th->Minimum;
}
printf("Final Max : %d ",totalMaximum);
printf("Final Min : %d ",totalMinimum);
return 0;
}
void *thread_search_min_max(void *para)
{
struct MaxMin *mp;
mp=(struct MaxMin*)malloc(sizeof(struct MaxMin));
int Count;
mp->Maximum=array[arraySize/2];
mp->Minimum=array[arraySize/2];
for(Count=arrSize/2 + 1;Count<arrSize;Count++)
{
if(array[iCount] > mp->Maximum)
{
mp->Maximum=array[Count];
}
if(array[Count] < mp->Minimum)
{
mp->Minimum=array[Count];
}
}
pthread_exit((void*)mp);
}