{"id":738,"date":"2023-09-03T13:11:23","date_gmt":"2023-09-03T13:11:23","guid":{"rendered":"https:\/\/learnlearn.uk\/ibcs\/?page_id=738"},"modified":"2023-09-05T07:21:37","modified_gmt":"2023-09-05T07:21:37","slug":"queues","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/ibcs\/queues\/","title":{"rendered":"Linear Queue"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Linear Queue<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Linear Queue<\/h3>\n<p><a href=\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignright size-medium wp-image-763\" src=\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-300x300.png\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-300x300.png 300w, https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-150x150.png 150w, https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-768x768.png 768w, https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue.png 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail.<\/p>\n<h3>Applications<\/h3>\n<p>Linear queues are typically used for:<\/p>\n<ul>\n<li>Task Scheduling: Managing processes and tasks in operating systems.<\/li>\n<li>Print Job Management: Handling print jobs in printers.<\/li>\n<li>Breadth-First Search (BFS): Graph traversal in algorithms.<\/li>\n<li>Data Buffering: Ensuring orderly data transfer in networking.<\/li>\n<li>Print Spooling: Managing print requests in systems.<\/li>\n<li>Call Center Systems: Handling incoming customer calls.<\/li>\n<li>Customer Service Chatbots: Processing customer inquiries.<\/li>\n<li>Data Processing Pipelines: Sequential data processing.<\/li>\n<li>Order Processing: Fulfilling customer orders in retail.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Operations<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Queue Operations<\/h3>\n<p><strong>Enqueue<\/strong><br \/>\nAdding an element to the back (also known as the rear or tail) of the queue.<\/p>\n<p><strong>Dequeue<\/strong><br \/>\nRemoving and returning the element from the front (also known as the head) of the queue.<\/p>\n<p><strong>Peek<\/strong><br \/>\nViewing the element at the front of the queue without removing it.<\/p>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Demo<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Linear Queue Interactive Demonstration<\/h3>\n<p><iframe style=\"width: 100%; height: 500px;\" src=\"https:\/\/learnlearn.uk\/wp-content\/uploads\/2023\/09\/linear_queue_demo.html\"><\/iframe><\/p>\n\n<\/div><h2 class=\"tabtitle\">Code<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Linear Queue Python Code<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0000aa;\">class<\/span> <span style=\"color: #00aa00; text-decoration: underline;\">LinearQueue<\/span>:\r\n    <span style=\"color: #0000aa;\">def<\/span> <span style=\"color: #00aa00;\">__init__<\/span>(<span style=\"color: #00aaaa;\">self<\/span>):\r\n        <span style=\"color: #00aaaa;\">self<\/span>.queue = []\r\n\r\n    <span style=\"color: #0000aa;\">def<\/span> <span style=\"color: #00aa00;\">enqueue<\/span>(<span style=\"color: #00aaaa;\">self<\/span>, item):\r\n        <span style=\"color: #00aaaa;\">self<\/span>.queue.append(item)\r\n\r\n    <span style=\"color: #0000aa;\">def<\/span> <span style=\"color: #00aa00;\">dequeue<\/span>(<span style=\"color: #00aaaa;\">self<\/span>):\r\n        <span style=\"color: #0000aa;\">if<\/span> <span style=\"color: #0000aa;\">not<\/span> <span style=\"color: #00aaaa;\">self<\/span>.is_empty():\r\n            <span style=\"color: #0000aa;\">return<\/span> <span style=\"color: #00aaaa;\">self<\/span>.queue.pop(<span style=\"color: #009999;\">0<\/span>)\r\n        <span style=\"color: #0000aa;\">else<\/span>:\r\n            <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Queue is empty\"<\/span>)\r\n\r\n    <span style=\"color: #0000aa;\">def<\/span> <span style=\"color: #00aa00;\">is_empty<\/span>(<span style=\"color: #00aaaa;\">self<\/span>):\r\n        <span style=\"color: #0000aa;\">return<\/span> <span style=\"color: #00aaaa;\">len<\/span>(<span style=\"color: #00aaaa;\">self<\/span>.queue) == <span style=\"color: #009999;\">0<\/span>\r\n\r\n    <span style=\"color: #0000aa;\">def<\/span> <span style=\"color: #00aa00;\">size<\/span>(<span style=\"color: #00aaaa;\">self<\/span>):\r\n        <span style=\"color: #0000aa;\">return<\/span> <span style=\"color: #00aaaa;\">len<\/span>(<span style=\"color: #00aaaa;\">self<\/span>.queue)\r\n\r\n<span style=\"color: #aaaaaa; font-style: italic;\"># Example usage:<\/span>\r\n<span style=\"color: #0000aa;\">if<\/span> __name__ == <span style=\"color: #aa5500;\">\"__main__\"<\/span>:\r\n    queue = LinearQueue()\r\n    queue.enqueue(<span style=\"color: #009999;\">1<\/span>)\r\n    queue.enqueue(<span style=\"color: #009999;\">2<\/span>)\r\n    queue.enqueue(<span style=\"color: #009999;\">3<\/span>)\r\n\r\n    <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Queue:\"<\/span>, queue.queue)\r\n    <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Dequeue:\"<\/span>, queue.dequeue())\r\n    <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Queue:\"<\/span>, queue.queue)\r\n    <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Is empty?\"<\/span>, queue.is_empty())\r\n    <span style=\"color: #0000aa;\">print<\/span>(<span style=\"color: #aa5500;\">\"Size:\"<\/span>, queue.size())\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/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\">Google Slides<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linear Queue A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail. Applications Linear queues are typically used for: Task Scheduling: Managing processes and tasks in operating&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/ibcs\/queues\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Linear 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":"off","neve_meta_content_width":100,"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>Linear Queue - IB 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\/ibcs\/queues\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linear Queue - IB Computer Science\" \/>\n<meta property=\"og:description\" content=\"Linear Queue A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail. Applications Linear queues are typically used for: Task Scheduling: Managing processes and tasks in operating&hellip;&nbsp;Read More &raquo;Linear Queue\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/ibcs\/queues\/\" \/>\n<meta property=\"og:site_name\" content=\"IB Computer Science\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-05T07:21:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-300x300.png\" \/>\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\/ibcs\/queues\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/queues\/\",\"name\":\"Linear Queue - IB Computer Science\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\"},\"datePublished\":\"2023-09-03T13:11:23+00:00\",\"dateModified\":\"2023-09-05T07:21:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/queues\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/ibcs\/queues\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/queues\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"IB Computer Science\",\"item\":\"https:\/\/learnlearn.uk\/ibcs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linear Queue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#website\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"name\":\"IB Computer Science\",\"description\":\"- learnlearn..uk\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#organization\",\"name\":\"IB Computer Science\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png\",\"width\":300,\"height\":41,\"caption\":\"IB Computer Science\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linear Queue - IB 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\/ibcs\/queues\/","og_locale":"en_GB","og_type":"article","og_title":"Linear Queue - IB Computer Science","og_description":"Linear Queue A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail. Applications Linear queues are typically used for: Task Scheduling: Managing processes and tasks in operating&hellip;&nbsp;Read More &raquo;Linear Queue","og_url":"https:\/\/learnlearn.uk\/ibcs\/queues\/","og_site_name":"IB Computer Science","article_modified_time":"2023-09-05T07:21:37+00:00","og_image":[{"url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2023\/09\/queue-300x300.png"}],"twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/ibcs\/queues\/","url":"https:\/\/learnlearn.uk\/ibcs\/queues\/","name":"Linear Queue - IB Computer Science","isPartOf":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#website"},"datePublished":"2023-09-03T13:11:23+00:00","dateModified":"2023-09-05T07:21:37+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/ibcs\/queues\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/ibcs\/queues\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/ibcs\/queues\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"IB Computer Science","item":"https:\/\/learnlearn.uk\/ibcs\/"},{"@type":"ListItem","position":2,"name":"Linear Queue"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/ibcs\/#website","url":"https:\/\/learnlearn.uk\/ibcs\/","name":"IB Computer Science","description":"- learnlearn..uk","publisher":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/ibcs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/ibcs\/#organization","name":"IB Computer Science","url":"https:\/\/learnlearn.uk\/ibcs\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","contentUrl":"https:\/\/learnlearn.uk\/ibcs\/wp-content\/uploads\/sites\/25\/2022\/09\/LearnLearnLogowhite-300x41.png","width":300,"height":41,"caption":"IB Computer Science"},"image":{"@id":"https:\/\/learnlearn.uk\/ibcs\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/ibcs\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Linear Queue A linear queue, as described in the introduction, follows the FIFO (First-In-First-Out) principle. Elements are added at the rear and removed from the front. It has a fixed size and may become full, causing enqueue operations to fail. Applications Linear queues are typically used for: Task Scheduling: Managing processes and tasks in operating&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/738"}],"collection":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":12,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/738\/revisions"}],"predecessor-version":[{"id":780,"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/pages\/738\/revisions\/780"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/ibcs\/wp-json\/wp\/v2\/media?parent=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}