whm692003 wrote:
> Hi,
> 
> This is my first post so please dont flame immediately!
> 
> Can anyone lend any insight as to the possible answers for the 
> following questions?
> 
> Thanks!
> 
> ~ Wm
> 
> 1. explain the running time and space boundaries of the following 
> function: 
> int fib(int n) {
>   if(n==1 || n==2) {
>      return 1;
>    } else {
>       return fib(n-1) + fib(n-2);
>    }
> }

Don't do this.  Recursive functions have the tendency to overflow the 
stack.  Best case:  The application crashes.  Worst case:  You create an 
exploitable security vulnerability.


> 2. explain how to use this structure, with special emphasis on the 
> levels[0] member.
> struct MESSAGE (CMEBookUpdate, CMEMessage) {
>     struct Level { 
>         Price   buyPx;
>         Price   sellPx;
>         int     buyQuantity;
>         int     sellQuantity;
>         int     buyNumOrders;
>         int     sellNumOrders;
>     };
>     enum { MaxLevels = 6 }; 
>     char        tradingOrigin;      // B=Book
>     char        tradingMode;        // 0=Preopening 1=Opening 
> 2=Continuous
>     bool        bookChanged[MaxLevels];// Has the N-th best order 
> changed? 
>     Level       levels[0];          // one level is present for each 
> true in bookChanged 
> };

Don't do this either.  levels[] indicates some sort of dynamically sized 
chunk of memory.  Use Safe C++ Block or C++ std::vector to manage this 
sort of data instead of exceeding structure boundaries like this.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to