How can you write a C program or an algorithim or a "Mr. Spock"

How can you write a C program or an algorithim or a "Mr. Spock" kinda logical explanation for that matter, to...

Simulate 2 lifts on a 3+1 (underground) storey building.

I got that idea, while having a discussion with my wife and B-in-Law on my apartment lift. It's pretty interesting on how the logic works.

Any takers??

*Phew* Was busy with a lot of work.
THis is not very tricky but not easy either.

So, how do you implement it?
Taking a Spock-kinda approach.. I'lll go with only with one lift.

1. the data-str be a doubly linked list with a header and a trailer indicating the terrace and the basement resp.
2. a variable to trace the status of the lift -
0-stopped
1-moving up
-1-moving down
3. a pointer to trace the present position of the lift.

Any button press is considered as a request and is added as a node in the doubly linked list to maintain the sequence of building.

Consider a 10 storeyed building-
If U have []=3=7=9=[] and there s a request for 5th floor it is added as -
[]=3=5=7=9=[]

Now, if the pointer is at 7 and it is coming down towards 3 and a request for 5 comes to go down.( You can compare the direction wrt the 0-1--1 variable), then it has to stop at 5 as well and as it serves the request for 5th node and the guy has to go to 1st floor, it gets added as a new request and the old request viz node-5 gets deleted to form-[]=1=3=7=9=[]

This forms the central idea and any further validation can be done to facilitate to make it a better escalator.

We can try to implement the same with Qs as well but gets a little complicated.

===. The Lift may be considered stopped if there r no nodes in betn the header and the trailer-

[]<=>[]

Quite right there, but slow!! Performance is the criteria here, don't forget this is a real-time solution and is usually different from apps.

Settings bits in a word or maybe a double word and using MSB for direction would do the same job, but in better way, though the general idea remains the same for skeleton.

See Also
Unix Administrator Career Path

Have a Unix Problem
Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.