# 对链表进行插入排序
对链表进行插入排序。

插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。
每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。
插入排序算法:
示例 1:
输入: 4->2->1->3 输出: 1->2->3->4
示例 2:
输入: -1->5->3->4->0 输出: -1->0->3->4->5## template ```python class LRUCache: def __init__(self, capacity): """ :type capacity: int """ self.maxlength = capacity self.array = {} self.array_list = [] def get(self, key): """ :type key: int :rtype: int """ value = self.array.get(key) if value is not None and self.array_list[0] is not key: index = self.array_list.index(key) self.array_list.pop(index) self.array_list.insert(0, key) value = value if value is not None else -1 return value def put(self, key, value): """ :type key: int :type value: int :rtype: void """ if self.array.get(key) is not None: index = self.array_list.index(key) self.array.pop(key) self.array_list.pop(index) if len(self.array_list) >= self.maxlength: key_t = self.array_list.pop(self.maxlength - 1) self.array.pop(key_t) self.array[key] = value self.array_list.insert(0, key) ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```