Question: Develop C++ code 1 Longest prefix You are given an array of strings. You want to code a function to find the longest common prefix

Develop C++ code

1 Longest prefix You are given an array of strings. You want to code a function to find the longest common prefix string amongst this array of strings. If there is no common prefix, return an empty string . Note: the common prefix must be a prefix of all strings. For example, suppose the input array of strings is: [flower,flow,flight]. Then the output of the function is:: fl. As another example, suppose the input is: [dog,racecar,car]. Then the output is: . That is, there is no common prefix among the input strings. More specifically, your task is implementing a function (as shown in the header file: ECLongestPrefix.h): std::string ECLongestPrefix(int numStrings, const std::string *arrayStrings[]);

starter code:

#include "ECLongestPrefix.h"

#include

using namespace std;

// Implement the longest prefix function here...

std::string ECLongestPrefix(int numStrings, const std::string arrayStrings[])

{

// YW: this only serves as a starter code, which just print out the given array of strings

// Replace with your own code here...

for(int i=0; i

{

cout << arrayStrings[i] << " ";

}

cout << endl;

string strDummy;

return strDummy;

}

Header file

#ifndef EC_LONGEST_PREFIX_H

#define EC_LONGEST_PREFIX_H

#include

std::string ECLongestPrefix(int numStrings, const std::string arrayStrings[]);

#endif // EC_LONGEST_PREFIX_H

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!