How to merge shapefiles?

C C++ Merge Sort a Linked List problem...

  • Hi there- I am trying to use Merge Sort on a linked list. I have it for the most part but I need some help debugging my program. It's running, but its not giving the correct output. Instead it's simply reversing the order of the linked list, not sorting it in numerical order like it should. I have a base linked list class which I have created. This works perfectly and it useful for creating a linked list of different types of objects. Here is a link to this code, so you can see it and understand it. It's pretty simple, but since the merge sort I'm trying to do is being intergrated into the class, I'll let you see what the class looks like by itself first to get an understanding of it: http://www.hiddentreasurehosting.com/source/basiclinkedlist.cpp The basic linked list version has an Anything class, which you'll see can be inheritied by any other object and then you can use virtual and apply_to_all any function you like. Very useful for printing out the linked list while using different objects' print methods. Now here is the link to my current linked list source code which include the Merge Sort in the class and doesn't work: http://www.hiddentreasurehosting.com/source/linkedlistnotworking.cpp I may be going about it all wrong, but I am sure the algorithm itself is correct and I must have made some errors when trying to move it inside my program. I have gotten most of it from a very reliable source and compiled it outside of my class and it worked perfectly. In case you would like to see this in action, (the merge sort algorithm working perfectly) I've also included a link to that here: http://www.hiddentreasurehosting.com/source/msexample.cpp The problem I'm having is trying to integrate the two together, placing the Merge Sort right in the linked list class. Now when I am trying to move the Merge Sort in the Linked List I ran into a few problems. To make it easier to read/write from now on I'll refer to the basic working Linked List version as BLL and the version thats not working with Merge Sort as the MS. First off, you'll notice that in the BLL version, the line of code, "Link *realdata" is a protected member, but in the MS version I had to move it to "public" in order to be able to access the head of the linked list in the main like this, "mylist.merge_sort( &mylist.realdata );" I also think that maybe I am comparing the wrong piece of data in my merge sort comparisons. Just a guess, thats why I'm here for help. The list is being reversely sorted, not numerically sorted like it's supposed to be. (it might actually not even be reversely sorted, it could be a coincidence, i'm not sure) I just know it's not working and I can't figure out why. Thanks alot for your help on this one, if you have any questions/clairification needed, just post and I'll respond very promptly. Also if I get a good answer I'll leave a nice tip! Thanks alot for all the help!

  • Answer:

    Hi balzack-ga, Okay, I've added merge to your linked list code. I'm uploading the code to my server now. This link http://nms.lcs.mit.edu/~gch/google/mergesort.zip will be active shortly. dogbite-ga

balzack-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.