Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago