Can anyone assist me in writing a search algorithm for songs in a playlist designed to locate a particular song? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone assist me in writing a search algorithm for songs in a playlist designed to locate a particular song?

31st May 2019, 8:09 PM
Bianca Reynolds
5 Answers
+ 1
If the playlist is sorted, you can look for the song letter by letter (you may use binary search or any other algorithm, sololearn has courses about it, also has courses for sorting items) If it's not sorted, you should check each item until you find the song.
31st May 2019, 10:29 PM
Andres0b0100
Andres0b0100 - avatar
0
Ok. I am new to programming so would the best way to do it be as a string?
31st May 2019, 11:36 PM
Bianca Reynolds
0
An array of strings is the most basic way of doing it. You can iterate through the array (with a loop or iterator) and compare every song name with the needed one In C++ you could use strcmp function (included in <string.h>, use it if you use char arrays and not string objects) Also String objects may be compared using the == operator (i'm not sure but i think it's possible)
31st May 2019, 11:40 PM
Andres0b0100
Andres0b0100 - avatar
0
Thank you so much. I'm going to try and knock this out
31st May 2019, 11:41 PM
Bianca Reynolds
0
Ok, tell me if you have doubts or bugs
31st May 2019, 11:54 PM
Andres0b0100
Andres0b0100 - avatar