zoukankan      html  css  js  c++  java
  • Insertion sort list

    while hand-writing the code,I meet with some trivial problems,which greatly worries me.

    1.since it's a singly list, if we don't modify the list, we have to change the usual sort algorithm a bit , such as ,put the current max at the current end of the list rather than the min to the very front

    2.how to avoid revisit sorted part?

       first I intend to record a globalmax as a mark so that whenever a globalmax is met, it means that the following part has been sorted , but it can't handle 

    repeated data,such as 5 2 5 1 1, after one 5 is pushed till the end of the list, we can see that value field is changed to 2 5 1 1 5, and the next first 5 is located at pos with index 1 (start from 0),so it recognize 2 5 1 1 5 as sorted,which is wrong;

      so an optimized solution is to store the length of the list when finding the max element for the first time, so iteration list can be decremented by 1 each time

    3. NULL pointer and one element case ,which is usual edge handling

  • 相关阅读:
    DLX
    逆康托展开
    康托展开
    light oj 1427(ac自动机)
    hdu 2586 (lca-RMQ)
    约瑟夫问题
    C-运算符
    C-数据
    shell-流程控制
    python编程规范-最佳实践
  • 原文地址:https://www.cnblogs.com/warmfrog/p/3698321.html
Copyright © 2011-2022 走看看