In this example the aim is to extract words from a sentence that user entered. The example input and output can be below:
Input : sen bana bakma gülerken
Output: sen
bana
bakma
gülerken
First of all, I would like to introduce myself, I am an assistant professor at a state university in Türkiye. My department is Computer Education. I have been taught many courses and one of them is Algorithm Design and Development. In this course, I teach the theoretical knowledge and the practical application of using this theoretical knowledge in different algorithm programs. One of my favorite apps is Flowgorithm (developed by Devin Cook in 2007). It is a free program that allows to create programs using flowcharts.
In this example, I will try to explain in detail how to solve a problem in the flowgorithm program. This example is one of the challenging questions I ask my students. The solution may be a bit long so try to explain it piece by piece. I hope it will be clear to anyone who wants to learn the "algorithm of the program that randomly sorts the words of a entered sentence".
Firstly we need an array in which we will load the words we get from the given sentence. I created an array named as “kelimeler” (kelimeler means words in English).
I defined 20 for this array. Here I assumed that a sentence could be up to 20 words. This means that the user cannot enter a sentence of more than 20 words. If you think a long sentence will be entered, you should increase the array size. After that I created two variables to get the sentence from the user and collect the character in a single string (cumle is sentence and toplam is sum in English).
These two variables are important. Please do not forget that I created following variables based on the need during algorithm. And each integer variable should assigned to 0.
Now it is time to get sentence from the user. You need to add following flowchart elements to the algorithm.
Now, we need to get the words from the sentence. I will use the space in the sentence to separate each word. The logic here is to read every character, and if we encounter any spaces, transfer the characters we have collected so far into the array. To do this, I created the following part of the algorithm. As you can see below, topla variable is collecting each character until encountering space and then if we see space collected characters is stored in kelimeler array.
Please note that after the collected word is stored in kelimeler array, you have to assign the topla variable to the blank in order to get a new word. After this loop, we need to add following part to the algorithm to add the last word to the array. The reason to add such a part is that sentence is not finished with space.
This is the final part of the algorithm. After this, we only need a loop to show each word we collected.
In the above section, loop goes to a and a indicates the number of the words collected so far.