博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Insertion sort list
阅读量:7082 次
发布时间:2019-06-28

本文共 1017 字,大约阅读时间需要 3 分钟。

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

转载于:https://www.cnblogs.com/warmfrog/p/3698321.html

你可能感兴趣的文章
欲保长寿,先补亏损 —胡海牙
查看>>
数据容量进制转换
查看>>
Spring Cloud Zuul过滤器详解
查看>>
使用DOM4J创建一个新的XML文件
查看>>
VIM使用系列:搜索功能
查看>>
SOAP--------Golang对接WebService服务实战
查看>>
7大维度看国外企业为啥选择gRPC打造高性能微服务?
查看>>
初创公司电商系统建立思考
查看>>
微服务框架Spring Cloud介绍 Part2: Spring Cloud与微服务
查看>>
linux系统下设置时间同步
查看>>
dubbo源码学习笔记----整体结构
查看>>
zipfile
查看>>
基于Dockerfile编译镜像并上传到Docker Hub公共仓库教程
查看>>
很形象地展示了进程与线程的区别
查看>>
代码即财富之我学Java比较器(7)
查看>>
记一次dubbo连接超时分析
查看>>
【译】Envoy threading model
查看>>
mysql主从复制
查看>>
karaf相关知识点
查看>>
鸥几里得算法,求两人个整数的最大公因数
查看>>