Ad
  • Default User Avatar

    No. When there are no letters in the string, the result is an empty string. This is when the behaviors are not equivalent:

    • In the first case, you try to delete a character that does not exist - since the string is empty. This is undefined behavior.

    • In the second case, you take a substring of the empty string, which is legal because result.size() - 1 will evaluate to (size_t)0 - 1 aka string::npos, and substr() specifies:

      A value of string::npos indicates all characters until the end of the string

  • Default User Avatar

    Read several times before understood what was going on. Probably better to emphasize that first the queue is sorted by priorities, then with every "known customer" swapping occurs.