{"id":16865,"date":"2022-07-02T21:24:55","date_gmt":"2022-07-02T19:24:55","guid":{"rendered":"https:\/\/www.valcon.it\/python\/?p=16865"},"modified":"2025-08-15T10:26:46","modified_gmt":"2025-08-15T08:26:46","slug":"classe-coda-list","status":"publish","type":"post","link":"https:\/\/www.valcon.it\/python\/classe-coda-list\/","title":{"rendered":"Classe coda, usa list"},"content":{"rendered":"\n<p>La classe <strong>Queue<\/strong> utilizza una lista<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Queue:\n    def __init__(self):   \n        self._lista=&#x5B;]\n    def enqueue(self, x): \n        self._lista.insert(0, x)\n    def dequeue(self):    \n        return self._lista.pop()\n    def is_empty(self):   \n        return (len(self._lista) == 0)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Test 1<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Queue:\n    ...\n \ncoda=Queue()            # &#x5B;]\n \ncoda.enqueue(18)        # &#x5B;18] \ncoda.enqueue(1)         # &#x5B;1, 18] \ncoda.enqueue(28)        # &#x5B;28, 1, 18]\n \nprint(coda.is_empty())  #             False\nprint(coda.dequeue())   # &#x5B;28, 1]     18\n \nprint(coda.is_empty())  #             False\nprint(coda.dequeue())   # &#x5B;28]        1\n \nprint(coda.is_empty())  #             False\nprint(coda.dequeue())   # &#x5B;]          28\n \nprint(coda.is_empty())  #             True\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Test 2<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass Queue:\n    ...\n  \ncoda = Queue()                      # &#x5B;]\n \nfor x in range(5):                 \n    coda.enqueue(x)\nprint(coda._lista)                  # &#x5B;4, 3, 2, 1, 0]\n \nwhile(not coda.is_empty()): \n    print(coda.dequeue(), end=&quot; &quot;)  # 0 1 2 3 4\nprint()\nprint(coda._lista)                  # &#x5B;]\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Continua&#8230;<\/h2>\n\n\n\n<p>Aggiungi i metodi<\/p>\n\n\n\n<ul>\n<li>x &lt;&#8211; <strong>top<\/strong>(), il primo elemento inserito?<\/li>\n\n\n\n<li>x &lt;&#8211; <strong>bottom<\/strong>(), l&#8217;ultimo elemento inserito?<\/li>\n\n\n\n<li>n &lt;&#8211; <strong>size<\/strong>(), quanti elementi contiene la coda?<\/li>\n\n\n\n<li>&#8230;<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>La classe Queue utilizza una lista Test 1 Test 2 Continua&#8230; Aggiungi i metodi<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85],"tags":[],"_links":{"self":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/16865"}],"collection":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/comments?post=16865"}],"version-history":[{"count":22,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/16865\/revisions"}],"predecessor-version":[{"id":29355,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/posts\/16865\/revisions\/29355"}],"wp:attachment":[{"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/media?parent=16865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/categories?post=16865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.valcon.it\/python\/wp-json\/wp\/v2\/tags?post=16865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}