Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 :

// strA and strB 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 the empty string

short goesFirst(const std::string& strA , const std::string& strB );

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 any loops.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions