**Sort Words Length**

String → Harry Potter and the Order of the Phoenix

We need to find the length of each word in the string by just using simple two if statements, where we need to maintain one count and increment it unless we get a space or we get at last in the string and when we get space or we get at last in string we need to store it somewhere(i.e., Array, Linked-list, vector etc) and re-initialize the count to zero and continue.

Then we need to sort the list in which we have stored the counts.

Reference Code: -

Initialize count to zero

Traverse in the List from 0 to size-1

{

If ( string[index] not equal to space )

increment count.

If ( string[index] equal to space OR index equal to size-1 )

Push count in list & re-initialize count to zero.

}

Sort List .