BJ
BAN USER- 0of 0 votes
Answerswhy vector does not push_front ?
- BJ in India| Report Duplicate | Flag | PURGE
C++
Guys how about this , controlling the access using 4 mutexes.
#include <pthread.h>
#include <iostream>
using namespace std;
pthread_mutex_t m;
pthread_mutex_t a1,a2,b1,b2;
extern "C" void *fun1(void *)
{
pthread_mutex_lock(&a1);
cout<<endl<<"A1"<<endl;
pthread_mutex_unlock(&a1);
pthread_mutex_lock(&b2);
pthread_mutex_lock(&b1);
cout<<endl<<"A2"<<endl;
pthread_mutex_unlock(&b1);
pthread_mutex_unlock(&b2);
return NULL;
}
extern "C" void *fun2(void *)
{
pthread_mutex_lock(&b1);
pthread_mutex_lock(&a1);
cout<<endl<<"B1"<<endl;
pthread_mutex_unlock(&a1);
pthread_mutex_unlock(&b1);
pthread_mutex_lock(&b2);
cout<<endl<<"B2"<<endl;
pthread_mutex_unlock(&b2);
return NULL;
}
main()
{
pthread_t thread_id1,thread_id2;
pthread_create(&thread_id1,NULL,&fun1,NULL);
pthread_create(&thread_id2,NULL,&fun2,NULL);
pthread_join(thread_id1,NULL);
pthread_join(thread_id2,NULL);
}
I really wonder if Polymorphism is the correct answer. In the below code the parent pointer points to a derived object, but compilation error will be thrown when this parent pointer tries to access a function which is there only in Derived class object
#include <iostream>
using namespace std;
class B
{
public: virtual void fun() {cout<<"Base"<<endl;};
};
class D2:public B
{
public: virtual void fun() {cout<<"der2"<<endl;};
public: virtual void OnlyInDerived() {cout<<"fun1"<<endl;};
};
main()
{
D2 d;
B *b=&d;
b->OnlyInDerived();
}
if the question is as simple I thought (unlike others)
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long double arr[3]={1,2,9},final =0;
int arrLength = 3;
for(int i=0;i<3;i++)
final = final +arr[i]*pow((double)10,arrLength-i-1);
final++;
cout<<"Value after adding 1: "<<final<<endl;
}
~
To be more precise if a parent process dies before "wait()ing" for a child process then the child process becomes orphan and the init process(pid=1) becomes the parent.
Init process periodically "wait()s" for all its child processes to make sure they end up being defunct/zombie.
Use a priority Queue.
Assuming each parking slot will be having a unique slot number associated with it.and lets also assume that parking spaces on the lower floors get more priority as compared to parking slots on higher floors.
When a new car comes in looking for a parking space just pick pop the top most entry from the Priroty Queue to get the best parking space.
Use a priority Queue.
Assuming each parking slot will be having a unique slot number associated with it.and lets also assume that parking spaces on the lower floors get more priority as compared to parking slots on higher floors.
When a new car comes in looking for a parking space just pick pop the top most entry from the Priroty Queue to get the best parking space.
Before calling free() on a pointer for which memory was allocated using new() call the destructor of that class and then invoke free();
The new() keyword does the below 2 operations
1.Allocate memory using malloc by invoking the "Operator new"
2.call the constructor.
The delete() keyword does the below 2 operations
1.call the destructor.
2.Deallocate the memory using free by invoking the "Operator delete"
Every user would be given default space during signup , and on every referral he would be given bonus space.The information related to bonus space can be stored in a map.
This map contains ReferredUser and bonus space .
To get total space of a user we should add default space and total free space acquired by referral.
- BJ August 30, 2013