Question: Write a recursive function to determine if strA goes before strB in a dictionary. Deciding whether to go first depends on the alphabetical order and

Write a recursive function to determine if strA goes before strB in a dictionary. Deciding whether to go first depends on the alphabetical order and the length of the strings. Make your function case insensitive i.e. upper and lower case letters are treated as being the same same: the case is ignored.

Do not make your solution quadratic. Use the function prototype

// p r e c o n d i t i o n :

// s trA and s t rB c o n t a i n l e t t e r s e x c l u s i v e l y , or are t h e empty s t r i n g

short g o e s F i r s t ( const s t d : : s t r i n g& strA , const s t d : : s t r i n g& s t rB ) ;

goesFirst returns 0 if strA is equal to strB a positive value if strA goes first in a dictionary i.e. strA is listed before strB

a negative value if strB goes first in a dictionary i.e. strB is listed before strA

Do not use string library functions nor C string functions except for the function length http://www.cppreference.com/wiki/string/length, at, and the overloaded operator [ ].

You may write your own helper function(s).

You may overload goesFirst if you need extra parameters.

Do not use magic numbers e.g. numeric ASCII codes.

Do not allocate any memory in the function goesFirst (nor when calling it) except for allocating a few int/short/char local variables: so do not use substr nor concatenation

Do NOT use loops.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!