> -----Original Message----- > From: pavaman subramanyam [mailto:pavamans@yahoo.co.in] > Sent: Wednesday, May 04, 2005 8:22 AM > To: UTTARA-owner@yahoogroups.com > Cc: uttara@yahoogroups.com > Subject: kindly post this query on uttara groups > > > Hi friends, > > I have some questions regarding how to solve these > problems. > > 1) A program that will change an arbitrary switch > statement with all its options into a collection of > if-else-if statements. > If the case values happen to be in order, you can apply binary search techinque. This will be efficient. For example, the following switch block - switch ( caseValue ) { case 12: /* ... */ break; case 4: /* ... */ break; case 14: /* ... */ break; case 20: /* ... */ break; default: /* ... */ break; } - can be written as - if ( caseValue >= 4 && caseValue <= 20 ) { if ( caseValue >= 4 && caseValue <= 12 ) { if ( caseValue == 4 ) { /* case 4 item goes here */ } else { /* case 12 item goes here */ } } else { if ( caseValue == 14 ) { /* case 14 item goes here */ } else { /* case 20 item goes here */ } } } else { /* default action */ } switch() statement was provided to avoid nested if-then-else. So, it should be preferred instead of if-then-else, wherever possible. > 2) A program to profile another program. It should > display how much time your program spends in > executing various blocks of code. Can you please help > me out about this. > This requirement cannot be met by a few lines of code. Tools, like gprof(1), exist to profile the your program. See "man gprof" for more details. > > Bye > PAVAMAN. S > > _