vendredi 23 janvier 2015

Binary Search scheme alteration


I'm having a bit of an issue with programming an algorithm..... below would involve some of the details of the assignment; now before you begin to say that I should actually attempt, in solving this problem. The assignment has already been grade yet, I'm unsatisfied with the conclusion or solution implemented. I'm pretty new to programing, and it becomes increasingly apparent as, I'm faced with an issue; I suppose my largest issue is the proper use of functions. I digress, I'd be happy to provide the actual code, which would be followed bellow assignment descriptions. Thanks


In C++, code a search algorithm that searches a list of strings for a particular song. The searching algorithm will have two inputs: the playlist, which is a string array that contains a list of songs in alphabetical order; and a particular song, which is a string. If the song is found in the list, the algorithm will return the index of the song, and it will return -1 otherwise. This searching algorithm will employ a divide-and-conquer approach similar to that in binary search, but with a slight variation. In binary search, a list is split in 2 sublists during each step; however, for your assignment, you will build and algorithm that splits the list into 3 sublists during each step.


INPUTS: the playlist, which is a string array that contains a list of songs in alphabetical order; and a particular song, which is a string. CONDITION:


If the song is found in the list, the algorithm will return the index of the song, and it will return -1


ELSE: This searching algorithm will employ a divide-and-conquer approach similar to that in binary search, but with a slight variation. In binary search, a list is split in 2 sublists during each step;


OUTPUT: however, for your assignment, you will build and algorithm that splits the list into 3 sublists during each step.


|Interpretation,and Implementation of solution__yes, I'm a terrible programmer .|


include include


using namespace std;


void bindarySearchPly(string playlist[], int first, int mid, int scdmid2, int last, int y){



int index;


}


using namespace std;


int main() {



void *bindarySearchPly(int y);
index = &bindarySearchPly;

string song;

//inialization of array and array index
string playlst[250] = {"Welcome to JamRock","Jucy", "A G Cook feat. Hannah Diamond – Keri Baby", "Airhead – Believe", "Allie X – BITCH: XHIBIT 1","Alvvays – Archie, Marry Me", "Andy – Violence","Angel Olsen – Forgiven","Aphex Twin – minipops 67 [120.2][source field mix]", "Arca – Thievery", "Ariana Grande feat. The Weeknd – Love Me Harder",
"Azealia Banks – Ice Princess","Banks (prod Shlohmo) – Brain", "Baauer feat. Rae Sremmurd and AlunaGeorge – One Touch", "Beyonce feat. Nicki Minaj – ***Flawless (remix)",
"Bobby Shmurda – Hot Nigga","Bok Bok feat. Kelela – Melba’s Call" ,"Boothroyd – NYC", "Caribou – Can’t Do Without You", "Chance the Rapper & The Social Experiment – No Better Blues",
"Charli XCX – Boom Clap", "Danity Kane – Lemonade", "Danny L Harle – In My Dreams", "Dej Loaf – Try Me","DELS – RGB","Drake – 0-100/The Catch-Up", "Dutch E Germ – Black Sea", "Elliphant feat. MO – One More",
"Evian Christ – Salt Carousel","Father feat. iLoveMakonnen & Key! – Look At Wrist", "Felicita – Doves","FKA Twigs – Two Weeks", "Flying Lotus feat. Kendrick Lamar – Never Catch Me", "Future feat. Pharrell Williams, Pusha T – Move That Dope","GEoRGiA – Hard Lie This", "GFOTY – Bobby","Holly Herndon – Chorus", "iLoveMakonnen feat. Drake – Tuesday","Jamie xx – All Under One Roof Raving","Jelani Blackman – Twenty Three",
"Jessie Ware – Tough Love","Juce – Call You Out","Juicy J feat Nicki Minaj, Lil Bibby, Young Thug – Low","K9 – Untouchable","Kindness – This Is Not About Us","Kendrick Lamar – i",
"Kero Kero Bonito – Sick Beat","Keyshia Cole feat. Milla J, K Michelle, Lil Mo & Da Brat – Loyal (remix)","Kwamie Liv – Follow You","La Roux – Uptight Downtown","Lana Del Rey – Brooklyn Baby",
"Le1f – Boom","LV and Josh Idehen – Imminent","Lykke Li – Gunshot","Mapei – Don’t Wait","Mark Ronson feat. Bruno Mars – Uptown Funk","Meridian Dan – German Whip","Migos – Hit Em","Mozart’s Sister – Good Thing Bad Thing",
"Mr Mitch – Don’t Leave","Mumdance & Novelist – Take Time","Nicki Minaj – Anaconda","Ought – Today More Than Any Other Day","Palmistry – Protector SE5","PARTYNEXTDOOR feat. Drake – Recognize",
"Perfume Genius – Queen","Popcaan – Everything Nice","Rae Sremmurd – No Type","Raury – God’s Whisper","Rich Gang – Lifestyle","Rick Ross feat. Kanye West and Big Sean – Sanctified","Run The Jewels feat BOOTS – Early”,"
"Ryn Weaver – OctaHate","Schoolboy Q – Studio", "SD Laika – Meshes", "Shamir – If It Wasn’t True", "Shura – Touch", "Sia – Chandelier","Skepta – That’s Not Me”","Slackk – Ancient Dolphin","SOPHIE – Hard",
"Spooky Black – Without You","Sun Kil Moon – Ben’s My Friend","SZA – Sobriety","Tei Shi – Bassically","Tiga – Bugatti","Tinashe feat. Schoolboy Q – 2 On",
"Tink feat Jeremih – Don’t Tell Nobody","Tirzah – No Romance","TOPS – Change Of Heart", "QT – Hey QT","Vic Mensa – Down On My Luck","Vessel – Red Sex", "War On Drugs – Red Eyes","Wet – Don't Wanna Be Your Girl",
"Wiley – “On A Level", "Years & Years – Take Shelter", "YG feat. Lil Wayne, Rich Homie Quan, Meek Mill", "Nicki Minaj – My Nigga (remix)", "Young Fathers – War", "Young Thug – Danny Glover",
"Young Thug feat. A$AP Ferg & Freddie Gibbs – Old English","Zara Larsson – Rooftop"};


cout << "Welcome to Choose that song Musicbox!";

cout << "please specify the song you would like to listen too:";

cin >>song;
cin.ignore();

return 0;

}


int bindarySearchPly(string index, string playlist[], int first, int mid, int scdmid2, int last, string y){



//int mid = first/2;
//int last = mid+first/2;
//int scdMid = last+mid+first/2;

string y = song;


for (int i = 0; i< 150; i++){

mid = last + (first - last) / 2;
scdmid2 = first(first - mid) / 2;
string x;

if(index(y, playlist[mid])){ //potential error due to type conversion int and string && strcomp maybe considered as an not a function
index = mid;
cout << "Thank you, your selection has been identified located within index:" << playlist[i] << endl;
}else if (index(playlist[last]), y){
index = last = mid + 1;
cout << "Thank you, your selection has been identified located within index:" << playlist[i] << endl;
}else if (index(playlist[scdmid2], y){
index = mid = last - 1;
cout << "Thank you, your selection has been identified located within index:" << playlist[i] << endl;
}else{
cout << "unable to find music seleciton"<< endl;
}
return -1;
}
}




Aucun commentaire:

Enregistrer un commentaire