   merge sort a linked list.
  I'm having trouble thinking of ways to sort the data once its all split up. Atleast I think I've split the linked list up correctly. Can someone please point me in the right direction and/or tell me if there is any part of my code so far that isn't going to function properly?my code so far:#include <iostream>#include <list>#include <string>using namespace std;typedef int value;list<value> mergeSort(list<value> sortThis);list<value> split(list<value> splitThis, int beginning, int end, string side);int main(){int a;list<value> main;main.push_back(3);main.push_back(5);main.push_back(8);main.push_back(7);main.push_back(4);main.push_back(1);main.push_back(2);main.push_back(9);//mergeSort(main);while (main.size() > 0){main.pop_front();cout << "deleting" << endl;}cin >> a;return 0;}list<value> mergeSort(list<value> sortThis){if ( sortThis.size() == 1 )return sortThis;int middle = sortThis.size()  / 2 ;list<value> left = mergeSort(split(sortThis, 0, (middle - 1), "left"));list<value> right = mergeSort(split(sortThis, middle, sortThis.size(), "right"));list<value> result;return result;}list<value> split(list<value> splitThis, int beginning, int end, string side){list<value> result;list<value> holder = splitThis;int count = beginning;if ( side == "left" ) {while ( count < end ){result.push_back(holder.front());holder.pop_front();count++;}} else if ( side == "right" ) {while ( count < end ){if ( count < beginning ){holder.pop_front();} else {result.push_back(holder.front());holder.pop_front();count++;}}}return result;}
  Is there any reason you aren't using list::sort() or list::merge()?   ;  Mostly because I do not know if the assignment will allow for those or not, I don't want to take the chance. Also I just like knowing somewhat how things work.Isn't there also a splice function i could of used instead of splitting the way i did? or does splice work differently.edit - scratch what i said, I will try it with merge and sort first so I can get it working than try to replace merge and sort with my own stuff after.[Edited by - KBakerSR on May 22, 2009 1:53:32 PM];  Alright i threw in a merge and sort, where i think they go but apparently not. It compiles fine but it crashes at runtime and opens a file called "xutility". new code with merge and sort:#include <iostream>#include <list>#include <string>using namespace std;typedef int value;list<value> mergeSort(list<value> sortThis);list<value> split(list<value> splitThis, int beginning, int end, string side);int main(){int a;list<value> main;main.push_back(3);main.push_back(5);main.push_back(8);main.push_back(7);main.push_back(4);main.push_back(1);main.push_back(2);main.push_back(9);mergeSort(main);while (main.size() > 0){cout << main.front();main.pop_front();cout << "deleting" << endl;}cin >> a;return 0;}list<value> mergeSort(list<value> sortThis){if ( sortThis.size() == 1 )return sortThis;int middle = sortThis.size()  / 2 ;list<value> left = mergeSort(split(sortThis, 0, (middle - 1), "left"));list<value> right = mergeSort(split(sortThis, middle, sortThis.size(), "right"));left.sort();right.sort();left.merge(right);list<value> result = left;return result;}list<value> split(list<value> splitThis, int beginning, int end, string side){list<value> result;list<value> holder = splitThis;int count = beginning;if ( side == "left" ) {while ( count < end ){result.push_back(holder.front());holder.pop_front();count++;}} else if ( side == "right" ) {while ( count < end ){if ( count < beginning ){holder.pop_front();} else {result.push_back(holder.front());holder.pop_front();count++;}}}return result;}[Edited by - KBakerSR on May 22, 2009 3:19:50 PM];Quote:Original post by KBakerSRint middle = sortThis.size()  / 2 ;list<value> left = mergeSort(split(sortThis, 0, (middle - 1), "left"));list<value> right = mergeSort(split(sortThis, middle, sortThis.size(), "right"));Your problem lies in the above lines. But I won't steal you the joys of debugging. Learn to use your debugger well, it's at least as important as knowing the lenguage of your choice. You have something called Call Stack (VS200x, I guess) which deserves to take a look into.Good luck.   ;  any good tutorials on using the microsoft visual studio 2008's debugger? I've never had to use a debugger before..lol. I've always took out a piece of paper and worked threw the problem by hand. The by hand method isn't working so well for this one tho.   ;Quote:Original post by KBakerSRany good tutorials on using the microsoft visual studio 2008's debugger? I've never had to use a debugger before..lol. I've always took out a piece of paper and worked threw the problem by hand. The by hand method isn't working so well for this one tho.I don't know of any, sorry, I learned the hard way. But it's quite easy. In the debugging menu you have lots of options and each entry shows the keyboard shortcut, e.g. F5 for running, F9 for toggling breakpoint, F10 for Step Over, F11 for Step into...Then, in the same menu you have a submenu labeled "Windows" which has several windows which give you lots of information. The most important ones could be:Automatic: it shows the variables which were accessed and changed in the last instruction executed.Memory: Not for beginners, I guess. Shows you the contents of a memory address.Subproccess: Shows you a list of subproccess, and for each, the function they began execution and the function they are now in.Call Stack: Shows you the functions which were called, in reverse order. So if you have this code:int fun(){    CloseHandle ((HANDLE) NULL);}int main(){    fun();}and you run it in debug, the call to CloseHandle will crash (can't test right now, sorry).So the debugger will tell you there's no code and ask you if you want to see the disassembler. You click no, or yes, as you like, and then look into the Call Stack Window and you'll see a table with contents like this:[potentially lots of unknown functions/addressess  here]CloseHandle()fun()main()<br><br>Then if you doubleclick fun in the list, it will show you fun code with a green arrow showing the instruction after the call the code is into.<br><br>Hope this helps a bit.<br>BTW, I have used mostly VC2005, and the spanish version anyway, so the names could not be exactly as I typed them.<br>; Introduction to Debugging.   