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.
So, how do you implement it?
1. the data-str be a doubly linked list
with a header and a trailer indicating the terrace and the basement resp.
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-
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
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|