{"id":736,"date":"2020-06-08T06:25:20","date_gmt":"2020-06-08T06:25:20","guid":{"rendered":"http:\/\/learnlearn.uk\/alevelcs\/?page_id=736"},"modified":"2021-04-22T03:09:37","modified_gmt":"2021-04-22T03:09:37","slug":"queue","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/alevelcs\/queue\/","title":{"rendered":"Queue"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Introduction to Queues<\/h3>\n<p>A queue is a data structure that operates on a First In First Out (FIFO) principle.<\/p>\n<p>They work just like in real life queues where:<\/p>\n<ul>\n<li>new items are added to the rear of the queue (ENQUE)<\/li>\n<li>when an items is removed the item at the front of the queue is removed first (DEQUE)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Linear Queue<\/h2>\n<div class=\"tabcontent\">\n\n<p><strong>Linear Queue<\/strong><\/p>\n<p>A linear queue works exactly as in real life. When you go to stand in the queue you just stand at the rear, but when the person at the front of the queue has finished being served everyone else in the queue has to shuffle forward a little bit. This is highly inefficient as each item in the array holding the queue has to be moved along by one position. If your queue is 1 million items long you will need to move 1 million items!<\/p>\n<p>We need a more efficient solution and for this we can use a circular queue.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Circular Queue<\/h2>\n<div class=\"tabcontent\">\n\n<p><strong>Circular Queue<\/strong><\/p>\n<p>In a circular queue, you keep track of the index of the front and rear of the queue.<\/p>\n<ul>\n<li>Each time you add a new item to the queue, you add it to the new empty space and then you increment the rear index by one.<\/li>\n<li>Each time you remove an item from the front of the queue you remove it and then increment the front index by one.<\/li>\n<li>If either index is equal to the length of the array then you need to reset that index to zero.<\/li>\n<\/ul>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a class=\"lazy-load-youtube preview-lazyload preview-youtube\" href=\"https:\/\/www.youtube.com\/watch?v=-GxuQ-Y8sbA\" data-video-title=\"Circular Queue ( Step by Step Animation )\" title=\"Play video &quot;Circular Queue ( Step by Step Animation )&quot;\">https:\/\/www.youtube.com\/watch?v=-GxuQ-Y8sbA<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=-GxuQ-Y8sbA\" title=\"Circular Queue ( Step by Step Animation )\">Circular Queue ( Step by Step Animation ) (https:\/\/www.youtube.com\/watch?v=-GxuQ-Y8sbA)<\/a><\/noscript><\/div>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Queue Methods<\/h2>\n<div class=\"tabcontent\">\n\n<p>Queue Methods<\/p>\n<p>Here are the standard queue methods:<\/p>\n<p><strong>Enqueue<\/strong><\/p>\n<p>This is where an item is added to the rear of the queue<\/p>\n<p><strong>Dequeue<\/strong><\/p>\n<p>This is where an item is removed from the front of the queue and returned to the program.<\/p>\n<p><strong>Peek<\/strong><\/p>\n<p>This is where the item at the front is returned, without removing the item from the queue.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Python Queue<\/h2>\n<div class=\"tabcontent\">\n\n<p><iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/e7a93c7645\" width=\"100%\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n<\/div><h2 class=\"tabtitle\">Resources<\/h2>\n<div class=\"tabcontent\">\n\n<p><a href=\"https:\/\/docs.google.com\/presentation\/d\/1fOis4OyXRg7hnt1Fq_A23dwj-eehiWZBu3DOkJf3mNs\/edit?usp=sharing\">Queues &#8211; Teacher Presentation<\/a><\/p>\n<p><a href=\"https:\/\/visualgo.net\/en\/list?slide=1\">Link List (can use to implement a queue)<\/a><\/p>\n<p><strong>Exam Questions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to Queues A queue is a data structure that operates on a First In First Out (FIFO) principle. They work just like in real life queues where: new items are added to the rear of the queue (ENQUE) when an items is removed the item at the front of the queue is removed first&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Queue<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"on","neve_meta_content_width":85,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Queue - A Level Computer Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Queue - A Level Computer Science\" \/>\n<meta property=\"og:description\" content=\"Introduction to Queues A queue is a data structure that operates on a First In First Out (FIFO) principle. They work just like in real life queues where: new items are added to the rear of the queue (ENQUE) when an items is removed the item at the front of the queue is removed first&hellip;&nbsp;Read More &raquo;Queue\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\" \/>\n<meta property=\"og:site_name\" content=\"A Level Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-22T03:09:37+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\",\"name\":\"Queue - A Level Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\"},\"datePublished\":\"2020-06-08T06:25:20+00:00\",\"dateModified\":\"2021-04-22T03:09:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/queue\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/alevelcs\/queue\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/queue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"A Level Computer Science Home\",\"item\":\"https:\/\/learnlearn.uk\/alevelcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Queue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"name\":\"A Level Computer Science\",\"description\":\"CIE Specification\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#organization\",\"name\":\"A Level Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"A Level Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Queue - A Level Computer Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/alevelcs\/queue\/","og_locale":"en_GB","og_type":"article","og_title":"Queue - A Level Computer Science","og_description":"Introduction to Queues A queue is a data structure that operates on a First In First Out (FIFO) principle. They work just like in real life queues where: new items are added to the rear of the queue (ENQUE) when an items is removed the item at the front of the queue is removed first&hellip;&nbsp;Read More &raquo;Queue","og_url":"https:\/\/learnlearn.uk\/alevelcs\/queue\/","og_site_name":"A Level Computer Science","article_modified_time":"2021-04-22T03:09:37+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/alevelcs\/queue\/","url":"https:\/\/learnlearn.uk\/alevelcs\/queue\/","name":"Queue - A Level Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#website"},"datePublished":"2020-06-08T06:25:20+00:00","dateModified":"2021-04-22T03:09:37+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/queue\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/alevelcs\/queue\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/alevelcs\/queue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"A Level Computer Science Home","item":"https:\/\/learnlearn.uk\/alevelcs\/"},{"@type":"ListItem","position":2,"name":"Queue"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/alevelcs\/#website","url":"https:\/\/learnlearn.uk\/alevelcs\/","name":"A Level Computer Science","description":"CIE Specification","publisher":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/alevelcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/alevelcs\/#organization","name":"A Level Computer Science","url":"https:\/\/learnlearn.uk\/alevelcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/alevelcs\/wp-content\/uploads\/sites\/20\/2019\/09\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"A Level Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/alevelcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/alevelcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Introduction to Queues A queue is a data structure that operates on a First In First Out (FIFO) principle. They work just like in real life queues where: new items are added to the rear of the queue (ENQUE) when an items is removed the item at the front of the queue is removed first&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/736"}],"collection":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":12,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/736\/revisions"}],"predecessor-version":[{"id":1962,"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/pages\/736\/revisions\/1962"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/alevelcs\/wp-json\/wp\/v2\/media?parent=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}