Merge sort not working

so i've been trying to write a merge sort algorithm for linked lists for an assignment and i'm so fing close, but it's really frustrating me because it isn't working correctly. i have a sort and a merge method and i'm doing this recursively. can someone point out what i'm doing wrong?? it prints the elements (i've been testing with random strings) and even changes their order, but no luck on them actually being sorted. help is massively appreciated.
sort method:
public static <T extends Comparable<T>> void sort(ADTListInterface<T> list){  
     int s = list.size();
if (s<2)return;
MyLinkedList<T> listl = new MyLinkedList<T>();
MyLinkedList<T> listr = new MyLinkedList<T>();
int x=0;
for(; x<s/2; x++){
     listl.add(list.get(x));//add first half of list to new list
for(; x<s; x++){
     listr.add(list.get(x));//add rest of original list to new list
sort(listr);
sort(listl);
merge(listl, listr, list);     
merge method:
public static <T extends Comparable<T>> void merge(ADTListInterface<T> listl,ADTListInterface<T>
     listr,ADTListInterface<T> list){
     while(!listl.isEmpty() && !listr.isEmpty()){
          if(listl.get(0).compareTo(listr.get(0))<= 0){//select smaller element and put back in original list
               list.remove(listl.get(0));
               list.add(listl.get(0));
               listl.remove(0);
          else{
               list.remove(listr.get(0));
               list.add(listr.get(0));
               listr.remove(0);
     //if anything is left in remaining lists put elements into original list
     while(!listl.isEmpty()){
               list.remove(listl.get(0));
          list.add(listl.get(0));
          listl.remove(0);
     while(!listr.isEmpty()){
               list.remove(listr.get(0));
          list.add(listr.get(0));
          listr.remove(0);
}

i've been testing with random stringsIt would be better to test on specific things, eg from simple to complex. For example, test it with:
-an empty list
-"a"
-"a","b"
-"b", "a"
-"c","b","a"
continue until your sorting fails, then find out why it fails there and not on the previous test.

Similar Messages

  • Merge call not working in ios7 on Iphone5

    Merge call not working in ios7 on Iphone5 ?

    Same here. We have this call center in our company where after i have added a call to merge i have to push no. 4 and dial from the keypad. This has never been possible in ios but it have been possible to create a contact called "Merge" and add number 4 as it's phone number. Now by merging first my clients call to my collegegue and then to this "Merge" contact it has been dropping me out of line and my client and collegue are merged.
    Now ios 7 wont let me call to this "Merge" contact's number "4"

  • Merge Sort - 'almost' working

    Hello everyone!
    I have been learning how to program for a while and I thought it came time for algorithms. I bought Cormen's book and everything was going smoothly until it came to Merge Sort. I understand the theory but I am having trouble putting it into practise. I found online a few (working) examples (like this one: http://goo.gl/75R0z) and I tried to look up to them and write my own code (with slight changes) and so far so unsuccessful. The code compiles but it doesn't do it's thing. Can you give me a hand?
    main function:
    http://pastebin.com/y0HZ7Dkj
    Here's the algorithm:
    http://pastebin.com/U8XAKsiv

    BR41N-FCK wrote:
    If I had a project with a short deadline - sure, I'd use a pre-made (what else can we call it?) solution. But right now I am learning algorithms, so there's no point using ready ones.
    The only reason for the sorting and linked-list exercises is to give students some experience with challenging, but solvable problems in programming. Don't get me wrong, there is great value in that. However, it would be better done in C or even Pascal. Computer Science teaching kind of went off the deep end in 1990 or and has only gotten worse.
    Thank you for solving my problem. It was so simple... and maybe that's why I have overlooked it :-)
    One of the skills a programmer must have is how to debug such problems. That doesn't always mean running in a debugger. I very rarely use a debugger. Most modern, UI or server work is far too complex for such things. Simple "printf" statements are usually all that is required.
    Speaking of C++. Why would you call it awful? I mean it isn't the best for developing windowed apps (see: objective-c and c# on windows), but it is great for console ones and also it is good for education purposes thanks to its plain syntax (compared to c# and not to even mention the crazy syntax of objective-c).
    Because I wasted so much of my programming career on it. I suppose it was a valuable lesson. I suspose if someone had told me it was junk in 1995 I probably would have ignored them then. Now I have a decent store of tacit wisdom that is hard to explain. I just "know" when someone does or doesn't know what they are talking about. Just because "everybody is doing it" doesn't mean everybody isn't wrong.
    Objective-C syntax is actually quite simple. It is just the message passing through brackets. That is insignificant compared to cryptic C++11. You aren't even using C++ in this program. With the expection of iostream, you are only using C. I don't see any templates, no references, no const-correctness, no virtual functions, no inline code, no iterator traits, no lambdas, no locales, no iomanips. It's all junk that only makes life harder and life is short enough as it is.

  • Sorting not working correctly for date field in alv report

    Hi All,
    My report displays many rows also containing date type fields of bldat,budat .
    When I sort the report selecting field of type bldat budat the sorting is not correct for the year.
    Ex:
    Invoice doc dat
    01-25-2011
    01-21-2011
    02-02-2011
    10-25-2010
    11-20-2010
    If I use ascending then it is sorted as :
    Invoice doc dat
    01-21-2011
    01-25-2011
    02-02-2011
    10-20-2010
    10-25-2010
    Why the sorting is not working correct for year.(2010 records should have been first).
    The field wa_tab-bldat is of type char10.
    It is populated as wa_tab-bldat = bsak-bldat.
    Kindly suggest what can be done.

    The field wa_tab-bldat is of type char10
    Then what it does is correct.
    Refer to type datum...it will work

  • Content Search Web Part - Sorting not working

    I recently tried the new Content Search Web Part for which i see tremendous potential. I wanted to use it to show a certain type of pages and that was not a problem (i added a url as the source where i got the pages from). I mapped the correct fields so
    that it showed image, title and modified date. I then tried the advanced mode and told it to sort by the modified date, however any way I tried to apply this sort it just would not save my settings and reverted back to the default sorting. Is there anything
    else you need to do to get Sorting to work?
    /Anders

    I hadn't tried looking with REST, but that's a good suggestion.
    In the interim, I found this on TechNet:
    http://technet.microsoft.com/en-us/library/jj679902.aspx#BKMK_MapCPtoRefinableMP<o:p></o:p>
    When you search for a crawled property, you may find two crawled properties
    that represent the same content. For example, a site column of type Text named
    Color will during crawl discover two crawled properties: ows_Color and
    ows_q_TEXT_Color. Crawled properties that begin with either ows_r<four
    letter code>, ows_q<four letter code>, or ows_taxId are automatically
    created crawled properties. When you select a crawled property to map to a
    refinable managed property, make sure that you don't map the automatically
    created crawled property. Instead, always map the crawled property that begins
    with ows_.
    So clearly (as clearly as the doc makes it) I need to use ows_ArticleStartDate. I've made sure that crawled property is the one I'm using, but I'm still not seeing any effect.
    As for the sorting model, that only seems to be relevant for Rank sorting, right?
    M.
    Sympraxis Consulting LLC -
    Marc D Anderson's Blog - @sympmarc -
    jQuery Library for SharePoint Web Services (SPServices)

  • Merge call not working

    I tried to initiate a 3 way call using an Apple 5s, and it did not work.  I am traveling in Toronto, could that have something to do with it?

        @DanPetrie
    Let's see what 3 way / Conference calling options are available to you.  Please share more details of what you experienced.  Were you on an existing call, trying to place another call to conference or were you attempting to accept a second incoming call to merge?  Please see more details about Call Conferencing in the Device Manual here: http://bit.ly/1ruLn6H on page 52.  Thanks!
    AnthonyTa_VZW
    Follow us on Twitter @VZWSupport

  • Merge statement not working over db link

    I have a merge statement that works fine when it's run against a local table, but when I try to run it against a table over a database link, I get the following error.
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-02063: preceding line from REPOS
    ORA-06512: at "DBADMIN.PING_DB", line 6
    ORA-06512: at line 1
    Here is the code:
    create or replace procedure ping_db
    as
    begin
    merge into availability@repos A
    using (select trunc(sysdate) from dual)
    on (trunc(A.day) = trunc(sysdate))
    when matched then update set A.uptime = A.uptime + 1
    when not matched then insert (hostname,dbname,day,uptime) values
    (utl_inaddr.get_host_name,sys.database_name,trunc(sysdate),1);
    commit;
    end;
    /Code compiles fine, but gets the error when it's executed. Any help would be appreciated.

    9.2.0.x is the version (9.2.0.4,.5 and .6)

  • Table Sorter Not working in EP 7.01

    Hi All,
    The table sorter stopped working in ep 7.01.
    Can anyone comment why?
    Are there any notes or patches to be applied?
    Thanks and Regards,
    Nuzhat

    Hi Shanti,
    Thanks for replying.
    I am working on WD for Java.
    Can you please give me your table sorter Java file?
    I think there may be issues in versions.
    Previous server was ep 7.00 and now when code is moved to ep 7.01 sp05 patch 1, the table sort doesnt seems to work. even though I checked all the codes are there in the new system.
    Thanks and Regards,
    Nuzhat

  • Sorting not working inside xml format

    Ok I know my title is not clear, but I have a table that is
    called with a spry if, inside another spry data set, and I have
    been having quite a bit of trouble with it. The sorting and even
    odd would not work....(though they work on the same table with the
    same source if it is not inserted within the spry data set) I
    worked on it quite a while yesterday (got it updated to 1.6 )and
    finally got the even/odd to work using the 'other' class from one
    of your examples....that is after trying every even odd combination
    I could think of....but I still can't get it to sort.
    <table id="sortable" width="100%"
    spry:if="'{formcriteria}'=='yes'">
    <tr>
    <th width="71%"
    spry:sort="dsAgentForms::formname">Form Name and Description
    </th>
    <th width="29%" spry:sort="dsAgentForms::formnum">Form
    Number</th>
    </tr>
    <tr spry:repeat="dsAgentForms" spry:even="dsAgentForms
    other" spry:hover="rowHover">
    <td height="28"><a
    href="{dsAgentForms::url}">{dsAgentForms::formname}</a></td>
    <td><a
    href="{dsAgentForms::url}">{dsAgentForms::formnum}</a></td>
    </tr>
    </table>
    you click on the "Forms & Applications" tab to see the
    table
    http://www.nmprc.state.nm.us/als2.htm
    I am using DW CS3 and it is fairly easy to insert a sortable
    table, but somehow, with this table being inside another spry data,
    it loses its sortability.
    you see in my code I am using
    spry:sort="dsAgentForms::formname" and I know this is not usual,
    the usual would be without the dsAgentForms:: part, but this was
    just the last thing I tried before posting. I thought that maybe
    because all the rest of the table needed the extra designation,
    that maybe the sorting did as well....

    I got it........it was the syntax of the spry:sort it needed
    the below instead of what I had
    spry:sort="dsAgentForms formnum">
    it was also the same error for the even odd, they now work
    with similar syntax
    thanks for the numerous examples you give us, I can get most
    anything I want to try to work if I have a working example
    :)

  • Merge Module not work at target machine

    Post Author: soky
    CA Forum: Other
    Hi all,
    I cannot deploy my RDC delphi application. This is very simple app, for trying base of using of rdc. Only one TApplication and a TCrystalActiveXReportViewer component on a form. Run nicely on developing machine. But the deploy drive me crazy
    Product: Crystal Reports Developer
    Version: 11.0.0.1282
    Patches Applied: 0
    Operating System(s):
      Developer: Windows XP home english
      Target: Windows 2000 5.00.2195 SP4 hungarian (version of msi.dll=2.0.2600.1183)
    I using InstallShield Express Borland Limited Edition. The build of release successfully with zero error, including merge modul CR11_rdc_runtime. But install broken the following error message:
    Internal Error 25001. 1615:
    RegistrationCosting::CostAllISSelfRegEntries::MsiDatabaseOpenView(hDatabase,_T("Select * from ISSelfReg"),hVieew)
    How can I make usable install stuff with this tools?
    Thanks, soky

    Can somebody tell me where I can find the log that will tell me whats going on with this module at startup.
    You say the module gets loaded, as does lsmod. So there will be no error message, as the system thinks the module is working(which it probably is). The reason your wireless is not working may be another issue. In order for some things to work correctly certain things need be loaded before other things can access them.
    anyway, all error logs are in /var/log, shouldn't take you long to look through them. They are dated.

  • Content search webpart sorting not working

    Using the Content Search webpart I have created a query that rollsup all the subsites of a particular path, which is working well. However, I have tried sorting using he sort by term SPSiteURL, unfortunatly that is not working. Does anyone have any idea
    what I am doing wrong.
    davidh

    Hi Cameron,
    Thanks for the reply. I find that hard to accept becuase I can get the same webpart to sort like I want it to at our SharePoint Online sites, granted the sorting feature is in a diferent location within the edit webpart dialog but still basically the same
    feature. Also, I would think that the SPSiteURL sort term does and should include the entire URL, which is unique to each site, which means that it should sort on the entire URL.
    I think that it is reasonable to expect to be able to achieve this in some manner, maybe not the way I am trying to do it, but I have to think I am not the first person to want to present the results of subsites sorted alpha-numerically.
    Thanks,
    davidh

  • Lightroom 3 - Capture Time Sort Not Working

    Sync of multi camera wedding shots not working. Camera's clocks are in sync. Files in folder will not sort using capture time. Any ideas on fix?

    What sort do you see when choosing "by capture time"? Do you see sorted by capture time within the individual cameras?
    A common problem causing this is having the clocks synchronized between several cameras, but being off by days, months or even years on one of the cameras.
    Beat

  • Merge calls not working

    My iPhone4, merge calls option is not working. Whenever I try to merge calls, it just show as it is going to a conference call, but suddenly gets closed. One call will be on hold and other call will be active but never works as a conference call. I used use this option very well a month before but now it is not working.

    I have tried to reset the settings and see if this works, but I still face the problem

  • Em.merge does not work while em.persist does?

    Hello,
    I have a stateless session bean with code snippets below.
        @PersistenceContext
        private EntityManager em;
        public void setList(ContainerList list, int key) {
            ContainerList stored = (ContainerList)em.find(ContainerList.class, key);
            list.setId(key);
            if (stored == null) { em.persist(list); }
            else {
                em.merge(list); // 1st alternative
    //            stored.copy(list); // 2nd alternative
    ...When I call the method setList for a non existing key, the entity is stored in the database. When I call the method for an existing key, the old value is not updated by the new, i.e. the merge method has no effect. If I comment out the 2nd alternative, it has no effect either. Does anyone has an idea why this does not work? I am using Netbeans 5.5 and 5.5.1 release candidate 1. (With the included application server.)

    Hello,
    I will try to summarise my knowledge of the JAVA persistence API as the documentation is not always clear and may be misleading.
    In SQL you have 4 main statements: INSERT, SELECT, UPDATE and DELETE.
    with
    @PersistenceContext
    private EntityManager em;some documentation appears to make the following associations:
    em.persist(Object entity) -> INSERT
    em.find(Class entityClass, Object primaryKey) -> SELECT
    em.merge(Object entity) -> UPDATE
    em.remove(Object entity) -> REMOVE
    However, practice shows that this is NOT the case!
    em.merge(Object entity) does exactly the same thing as em.find(Class entityClass, Object primaryKey)! The only difference is that the em.merge(Object entity) method takes a detached object of the entity class as argument with the same primary key as the attached object you are loading.
    Detached objects are objects of the entity class the database manager is not aware of. Attached objects are objects in the database and are managed by the persistence context. Every newly created object of an entity class is detached. You can attach them to the database with the em.persist(Object entity) method call. Attached objects can be retrieved with the em.find(Class entityClass, Object primaryKey) or with the em.merge(Object entity) method. All changes made to attached objects are automatically stored in the database. There thus is no explicit method for the UPDATE statement. You just make changes to attached objects and the entity manager copies the changes to the database (at the end of the persistence context). An easy way to make all the changes you need at once is to have a detached object that contains the right values and then copy all these values to the associated attached object with a self defined copy method in the entity class as in
       Entity detached;
    // --> begin persistence context
       Entity attached = em.merge(detached);
       attached.copy(detached);
    // <-- end persistence contextIf you are working with session beans, the persistence context standard begins with the beginning of a transaction and ends with the end of a transaction. A transaction standard begins with the start of a session bean method and ends with the session bean method. If you choose to, you can make the persistence context of type extended with
    @PersistenceContext(type=PersistenceContextType.EXTENDED)
    private EntityManager em;In this case, the persistence context ends when the session bean is removed from the EJB container. (Can be useful to keep attached entities in the state of an stateful session bean.)
    Without session beans, you have to declare explicitely the start and end of a persistence context or transaction, but I refer to existing documentation for this, as I do not actively know how to handle things without session beans.
    Finally, the methods em.persist(Object entity) and em.merge(Object entity) use a detached object as argument, while em.remove(Object entity) uses an attached object as argument (using a detached object results in an Exception thrown).
    I hope this makes some things clear

  • Sorting not working in a report with hyperlinks

    I have a report with hyperlinks for one column and I noticed that sorting is no longer working on that report. If I use another version of the same report witout hyperlinks; sorting does work fine.
    I was wondering if anyone has encountered this issue before and what would be the solution.
    Thanks!

    I didn't remove the sorts and was trying to sort again on another column.
    So this is resolved.
    Now another issue; when viewing this report in Interactive mode; the column with hyperlinks doesn't have the sort option when I right click on that column. The sort option does show up but it's grayed out (disabled). When I go to Edit mode; it does allow me to sort on that column.
    Anyone has noticed this?

Maybe you are looking for

  • "has encountered a problem and needs to close" 7de8_appcompat.txt

    Everytime I try to browse the internet I get "Firefox has encountered a problem and needs to close" the tech report shows C:\DOCUME~1\Owner\LOCALS~1\temp\7de8_appcompat.txt

  • Creating PDFs of drawings from ArcMap results in blank areas on the PDF

    I generate maps in ArcMap and when I make PDFs of the maps I get white or blank areas in the resulting PDF unless I generate it in High Quality mode. Anyone know what causes this? 

  • Backup How To

    Hello to all! With iOS 7 coming out some time soon, this fall according to Apple, it's time to make sure we all have good backups to make sure we don't loose anything. This is just an overview of how I make sure my stuff is backed up and safe.  All t

  • Glyph View in Character Viewer?

    Back in Snow Leopard, we had the possibility to view all characters of a certain font if we selected "View>Glyph" in the character viewer. In Lion, this option seems to be missing. Is there any way to browse all characters of a specific font? The rea

  • Posting incoming payment ismore than the net due

    Dear Experts, How can we do the transactions where in the customer incoming payment is more than the net due. with regards Ramesh Y