Here Jesus used an analogy to teach a lesson about that generation. First, let it be noted that the "marketplaces" in Jesus' day were open squares where men did business and children often played.
In 11:17, Jesus described two groups of children. The first group "played the flute" (or perhaps imitated its sound) in hopes that the second group would "dance" or rejoice (as in a wedding). However, this effort was unsuccessful. But, instead of giving up, the first group then proceeded to do just the opposite. They "mourned" in an attempt to get the second group to "lament" or grieve (as in a funeral). This too failed to produce any action in the second group.
Jesus began to make His application in 11:18. I believe the first group of children represents Jesus and John and the second group represents the Jews (particularly the religious leaders). Some believe the grammar requires the opposite interpretation, but such cannot be proven. Jesus' comments regarding His generation include the entire picture He set forth in 11:16-19, not just the first group of children who call to their companions (cf. Matt. 13:24,37 for a similar example of this type of grammatical "difficulty").
This interpretation unquestionably fits the immediate and remote contexts better than the alternative view. The manner in which John the baptizer lived did not please the Jews. However, when Jesus came and behaved in the opposite way physically, to a certain extent, the Jews still weren't pleased! The Jews wouldn't "lament" or "dance"! They were like spoiled children who were immature, selfish, and hard to please. Both John and Jesus called upon the people to repent and prepare for the kingdom of God, but the people rejected one as too strict and the other as too lenient. Most people were not moved to action (specifically, obedience) by either John or Jesus (although they should have been). Many tried to justify themselves by asserting that John had "a demon" and that Jesus was "a glutton and a winebibber." The fact of the matter was that neither claim had any merit. Jesus wasn't guilty of being a glutton or a drunkard any more than John was possessed by a demon! May we never be guilty of assuming that every negative thing that is stated about others is true, and may we not lose heart when others "say all kinds of evil against [us] falsely" for the Lord's sake (Matt. 5:11).
This section of text closes with Jesus declaring the following - "But wisdom is justified by her children" (Matt. 11:19). Some manuscripts have the Greek word for "works" instead of "children". The meaning would seem to be this: those who did understand and respond appropriately, by obeying the teachings of John and Jesus, would consequently show the wisdom in the approach these two men took. Although their number was few, there were some who were moved to action (specifically, obedience) by the ministries of these two godly men. Both John and Jesus were given a unique work to do, and each one accomplished that work in a distinct, yet divinely approved, way!