{"id":707,"date":"2026-03-24T17:08:00","date_gmt":"2026-03-24T09:08:00","guid":{"rendered":"https:\/\/mitongxue.cn\/?p=707"},"modified":"2026-07-16T20:51:19","modified_gmt":"2026-07-16T12:51:19","slug":"python%e5%ae%9e%e7%8e%b0%e6%8a%bd%e8%b1%a1%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"https:\/\/mitongxue.cn\/index.php\/2026\/03\/24\/python%e5%ae%9e%e7%8e%b0%e6%8a%bd%e8%b1%a1%e5%ba%8f%e5%88%97\/","title":{"rendered":"python\u5b9e\u73b0\u62bd\u8c61\u5e8f\u5217"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>from abc import ABC, abstractmethod\n\nclass Sequence(ABC):\n    @abstractmethod\n    def append(self, item):\n        pass\n\n    @abstractmethod\n    def get(self, index):\n        pass\n\n    @abstractmethod\n    def length(self):\n        pass\n\n    @abstractmethod\n    def __iter__(self):\n        pass\n\n    def is_empty(self):\n        return self.length() == 0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>class ListSequence(Sequence):\n    def __init__(self):\n        self._data = &#91;]\n\n    def append(self, item):\n        self._data.append(item)\n\n    def get(self, index):\n        return self._data&#91;index]\n\n    def length(self):\n        return len(self._data)\n\n    def __iter__(self):\n        return iter(self._data)\n\n\nclass Node:\n    def __init__(self, value):\n        self.value = value\n        self.next = None\n\n\nclass LinkedListSequence(Sequence):\n    def __init__(self):\n        self._head = None\n        self._size = 0\n\n    def append(self, item):\n        new_node = Node(item)\n        if self._head is None:\n            self._head = new_node\n        else:\n            current = self._head\n            while current.next:\n                current = current.next\n            current.next = new_node\n        self._size += 1\n\n    def get(self, index):\n        if index &lt; 0 or index >= self._size:\n            raise IndexError(\"index out of range\")\n        current = self._head\n        for _ in range(index):\n            current = current.next\n        return current.value\n\n    def length(self):\n        return self._size\n\n    def __iter__(self):\n        current = self._head\n        while current:\n            yield current.value\n            current = current.next<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[],"class_list":["post-707","post","type-post","status-publish","format-standard","hentry","category-python"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"author_info":{"info":["\u9648 \u67d0\u4eba"]},"category_info":"<a href=\"https:\/\/mitongxue.cn\/index.php\/category\/back\/python\/\" rel=\"category tag\">Python<\/a>","tag_info":"Python","comment_count":"0","_links":{"self":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=707"}],"version-history":[{"count":1,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":710,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/707\/revisions\/710"}],"wp:attachment":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}