Hello, could someone help me? I am having a very difficult time trying to grasp
ID: 3804803 • Letter: H
Question
Hello, could someone help me? I am having a very difficult time trying to grasp and understand the logic of advanced data handling and bubble-sorting in chapter 8 of "Programming Logic and Design Comprehensive 8th edition", which uses Visual Logic. I am having trouble with the second exercise, which reads:
"Design an application to a program that accepts 15 words and displays them in alphabetical order."
I know how to bubble sort names and ID's in Visual Logic, but I do not know how to make it so that it sorts words and alphabtizes them. Any help would be appreciated!
Thank you!
Explanation / Answer
f you are asking someone to write this for you, you might get some HELP with it if you put in some serious help first AND told us what language you were working in ...
Set counter to 0
while counter is < 15
do:
Ask user for a word
take entered word and store it in array words in the 'counter' position of the array (words[counter])
end while
Now create a recursive function while compares the letters of the words in each array position looking for the "lowest" value. If they are equal, advance one position in the string and compare again.
The recursive function would look something like:
counter2 = 0
if words[counter][counter2] is greater than [counter+1][counter2] then do switch the word position copying word 1 to word 2. If they are equal then perform the same check looking at [counter][counter2+1], and so on.
So you compare the first letter of words[0] with words[1] and keep moving to the next letter as long as the current letters are equal. Once you identify the "smallest" word (lowest letter in the alphabet) you then move to the next word. Using recursion means that you define the function once but then you call the next iteration of the function from within the function itself repeatedly until there are no more array elements (counter =words.length)
function Compare() {
....
function compareLetter()
{ .... }
How you do this depends upon the language. In C this would therefore be a two-dimensional array as it is an array of strings and strings are themselves arrays. So you would access the third letter of the second word in the array at words[1][2]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.