开发者

seat resv. problem

开发者 https://www.devze.com 2023-01-20 06:34 出处:网络
Reservation Problem there are 67 seats in train . there are only 5 seats in a row and in last row there are only 2 seats. One person can reserve only 5 seat at a time. If person reserving seat , the c

Reservation Problem there are 67 seats in train . there are only 5 seats in a row and in last row there are only 2 seats. One person can reserve only 5 seat at a time. If person reserving seat , the care is taken that he may get all in row. if seats are not available in row then the arrangement is so that person group get nearby seats.

the following class is given

public class seat
{
char name;
int seat;
boolean isSeatempty
}

Write function seatallot(int noofperson) to allocate seat with seat nuber printed for the each name.

This is a pr开发者_JAVA百科oblem i found in an interview paper. how do i go about it?? Should i check for all 67 seats objects in a loop?? esp. with the case of last row and the problem of giving seats nearby if full row is not available. Thanks in advance for help.


What is your thinking on defining "nearby"? One definition might be in as small a range as possible, but you could speculate on the layout/numbering and come up with something different.

I'd write two helper functions - findEmptySeatsInRow(n) to look for n seats in a complete row, then findNearbySeats(n) to find nearby seats if there isn't a row free.

I would expect some follow-on questions from the interviewer, too (maybe about concurrent access to the allocating function, or efficiency of allocating seats given - maximising the use of the carriage/meeting as many people's requests as possbible), so even if someone hands you a solution to the method, you're going to need to think about this yourself

EDIT: Also there are 623 Google matches for "There are 67 seats in train" so there's a lot of other information out there already about this one.

0

精彩评论

暂无评论...
验证码 换一张
取 消