Professional Documents
Culture Documents
Ap 1 B
Ap 1 B
h>
struct hosp
{
int maxstud;
int pref[20];
int seatsfilled;
int alloc[20];
};
struct hosp h[20];
struct stud
{
int pref[20];
int alloc;
};
struct stud s[25];
int m,n,totalseats=0;
void allocate()
{
int freecnt=totalseats;
while (freecnt > 0)
{
// Pick the first free man (we could pick any)
int i=0,j=0,k=0,l=0,p,q=0,freehosseat;
while(h[i].seatsfilled<h[i].maxstud)
{
if(h[i].pref[j]==s[k].pref[q])
if(s[k].alloc==-1)
{
s[k].alloc = i;
h[i].alloc[l++]=k;
h[i].seatsfilled++;
j++;
k++;
q++;
freecnt--;
}
else
{
for(p=0;s[k].pref[q]!='\0';p++)
if(s[k].alloc!=-1 && s[k].pref[p]==i)
{
freehosseat=s[k].alloc;
s[k].alloc=i;
h[i].alloc[l++]=k;
h[i].seatsfilled++;
}
}
i++;
j++;
} // End of the for loop that goes to all women in m's list
} // End of main while loop
}
int main()
{
int i,j,totalseats;