it is not complete.........u may need to do some modifications
Regards,
Bhanu
#include<stdio.h>
#include<pthread.h>
#include<signal.h>
struct lift
{
int status;
int movement;
}l[8];
struct floorno
{
int curfloor;
int destfloor;
}f[8];
int i;
void main()
{
int ch;
int j;
for (j=0;j<8;j++)
{
l[j].status=0;
l[j].movement=0;
}
pthread_t lift[8];
j=0;
while(1)
{
printf("enter the current floor no:\n");
scanf("%d",&f[j].curfloor);
printf("enter the destination floor no:\n");
scanf("%d",&f[j].destfloor);
pthread_creat(&lift[i],NULL,liftfn,(void*)i);
j=j+1;
if(j>7)
{
j=0;
}
while(1)
{
if(i<8)
break;
}
printf("is there any more users(1-Yes/0-No)\n");
scanf("%d",&Ch);
if(ch==0)
break;
}
}
void *liftfn(void*x)
{
int time=0,j=0,t=0,finalliftno=0,z=0,p=0;
int y;
y= *((int*)x);
if(((f[y].curfloor%2)==0)&&((f[y].destfloor%2)==0))
{
for(j=0;j<6;j++)
{
if(l[j].movement==0)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
t=z*2;
}
if(z<0)
{
t=z*(-3);
}
else if(z==0)
{
t=0;
}
if(j<2)
{
p=p+1;
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
if(p==0)
{
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
}
}
}
else if(((f[y]curfloor%2)!=0)&&((f[y].destfloor%2)!=0))
{
for(j=7;j>1;j--)
{
if(l[j].movement==0)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
t=z*2;
}
if(z<0)
{
t=z*(-3);
}
else if(z==0)
{
t=0;
}
if(j>5)
{
p=p+1;
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
else if(j==0)
{
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
}
}
}
else
{
for(j=2;j<6;j++)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
a {
if(l[j].movement==0)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
t=z*2;
}
if(z<0)
{
t=z*(-3);
}
else if(z==0)
{
t=0;
}
if(j<2)
{
p=p+1;
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
if(p==0)
{
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
}
}
}
else if(((f[y]curfloor%2)!=0)&&((f[y].destfloor%2)!=0))
{
for(j=7;j>1;j--)
{
if(l[j].movement==0)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
t=z*2;
}
if(z<0)
{
t=z*(-3);
}
else if(z==0)
{
t=0;
}
if(j>5)
{
p=p+1;
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
else if(j==0)
{
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
}
}
}
else
{
for(j=2;j<6;j++)
{
z=l[j].status-f[y].curfloor;
if(z>0)
{
t=z*2;
}
if(z<0)
{
t=z*(-3);
}
else if(z==0)
{
t=0;
}
if(time>t)
{
time=t;
finalliftno=j+1;
}
}
}
}
printf("you have to take lift no %d\n",finalliftno);
i=i+1;
l.[finalliftno-1].movement=1;
printf("lift no %dis coming to %d floor\n",finalliftno,l[y].curfloor);
if(z>0)
{
for(j=l[y].status;j>=j[y].curfloor;j--)
{
printf("the lift is now in floor number %d\n",j);
sleep(2);
}
}
else if(z<0)
{
for(j=l[y].status;j<=j[y].curfloor;j++)
{
printf("the lift is now in floor number%d\n",j);
sleep(3);
}
}
else if(z==0)
{
printf("the lift is in the floor %d\n",j[y].curfloor);
}
sleep(5);
printf("the lift is moving from %d(current floor)\n to %d(destination fl
oor)",j[y].curfloor,j[y].destfloor); 138,2-9 97%