Function/Array Question

Part 1

"Write a function that would take an array of strings, and sort it so that the strings appear in alphabetical order"

We don't know how big the array will be and I've never had any practice with functions/arrays of strings, please help!!

Part 2

How would I sort both arrays and then be able to compare their contents one by one? I need to write a function that determines whether two arrays of strings contain the same data regardless of order. So it should print "same" if they match and different if they don't basically but I'm completely lost again on how to do this with strings.
In normal, everyday C++, arrays whose size we don't know are called vectors and these functions would look something like this (give or take a few options in the second one)

1
2
3
4
5
6
void f1(std::vector<std::string>& v) { std::sort(v.begin(), v.end()); }
void f2(const std::vector<std::string>& v1, const std::vector<std::string>& v2) {
  std::set<std::string> s1(v1.begin(), v1.end()), s2(v2.begin(), v2.end());
  if(s1 == s2) std::cout << "same";
  else std::cout << "different";
}


but given that "I've never had any practice with functions/arrays of strings", it seems that you are not actually programming in C++, you're learning it following some course and to be helpful, the answer would be aware of what exactly you've been taught at this point.
Topic archived. No new replies allowed.