{"id":498,"date":"2023-02-13T02:45:50","date_gmt":"2023-02-13T02:45:50","guid":{"rendered":"https:\/\/aipsacademy.com\/blogs\/?p=498"},"modified":"2023-02-13T02:45:51","modified_gmt":"2023-02-13T02:45:51","slug":"queue-data-structure-in-c-best-example","status":"publish","type":"post","link":"https:\/\/aipsacademy.com\/blogs\/2023\/02\/13\/queue-data-structure-in-c-best-example\/","title":{"rendered":"Queue Data structure in C++ Best example"},"content":{"rendered":"\n<p><strong>What is Queue?<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Queue<\/strong>&nbsp;is a liner data structure.it means elements in this data structure have a unique predecessor and a unique successor.<\/li><li><strong>Queue follows<\/strong>&nbsp;First In First Out&nbsp;<strong>(FIFO<\/strong>) technique.<\/li><li>Initial value of Rear and Front is -1 which is known as centennial value.<\/li><li><strong>When&nbsp;<\/strong>new Element is inserted in a Queue then Rear is Incremented by one and this term is known as Enqueue.<\/li><li><strong>When&nbsp;<\/strong>&nbsp;an element is deleted from a Queue then Front is Incremented by one and this term is known as Dequeue.<\/li><li><strong>When&nbsp;<\/strong>there is no space for inserting new element and we try to insert then what situations comes known as Queue overflow i.e no space for insertion.<\/li><li><strong>When&nbsp;<\/strong>there is<strong>&nbsp;no element<\/strong>&nbsp;in Queue and&nbsp;<strong>we try to delete&nbsp;<\/strong>then what situations comes known as Queue&nbsp;<strong>underflow<\/strong>&nbsp;i.e no element for deletion.<\/li><li><strong>When<\/strong><a href=\"https:\/\/www.programiz.com\/dsa\/queue\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>&nbsp;<\/strong>Queue<\/a>&nbsp;is<strong>&nbsp;full<\/strong>&nbsp;then Rear will be at&nbsp;<strong>size-1<\/strong>.<\/li><li><strong>Queue&nbsp;<\/strong>can be represented or implemented in two ways.<\/li><li><strong>Queue as an&nbsp;<\/strong><a href=\"https:\/\/www.nipsacademy.com\/blogs\/arrays-in-c-language\/\"><strong>array<\/strong><\/a><\/li><li><strong>Queue as a linked list<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Types of Queue<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li><strong>Linear Queue<\/strong><\/li><li><strong>Circular Queue<\/strong><\/li><li><strong>Priority Queue<\/strong><\/li><\/ol>\n\n\n\n<p><strong>Linear Queue<\/strong><\/p>\n\n\n\n<p><strong>Algorithm: Insert Operation on&nbsp;<\/strong><strong>Queue<\/strong><\/p>\n\n\n\n<p>Step 1:<strong>&nbsp;If Rear=Max-1<\/strong><\/p>\n\n\n\n<p><strong>Print \u201cOverflow : Queue is full\u201d and Exit<\/strong><\/p>\n\n\n\n<p><strong>End If<\/strong><\/p>\n\n\n\n<p>Step 2:&nbsp;<strong>If Front=-1<\/strong><\/p>\n\n\n\n<p>Set&nbsp;<strong>Front =0<\/strong><\/p>\n\n\n\n<p><strong>End If<\/strong><\/p>\n\n\n\n<p>Step 3:&nbsp;<strong>Rear=Rear+1<\/strong><\/p>\n\n\n\n<p>Step 4:&nbsp;<strong>Queue[Rear]=Element<\/strong><\/p>\n\n\n\n<p>Step 5:&nbsp;<strong>End<\/strong><\/p>\n\n\n\n<p><strong>Algorithm: Delete Operation on Queue<\/strong><\/p>\n\n\n\n<p>Step 1:&nbsp;<strong>If Front=-1<\/strong><\/p>\n\n\n\n<p><strong>Print \u201cUnderflow: Queue is empty\u201d and Exit<\/strong><\/p>\n\n\n\n<p><strong>End if<\/strong><\/p>\n\n\n\n<p>Step 2:<strong>&nbsp;Set Del_element=Queue[Front]<\/strong><\/p>\n\n\n\n<p>Step 3:&nbsp;<strong>If Front=Rear<\/strong><\/p>\n\n\n\n<p>Set&nbsp;<strong>Front=Rear=-1<\/strong><\/p>\n\n\n\n<p><strong>Else<\/strong><\/p>\n\n\n\n<p><strong>Front=Front+1<\/strong><\/p>\n\n\n\n<p><strong>End If<\/strong><\/p>\n\n\n\n<p>Step 4:&nbsp;<strong>Return Del_Element<\/strong><\/p>\n\n\n\n<p>Step 5:&nbsp;<strong>End<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Queue? Queue&nbsp;is a liner data structure.it means elements in this data structure have a unique predecessor and a unique successor. Queue follows&nbsp;First In First Out&nbsp;(FIFO) technique. Initial value of Rear and Front is -1 which is known as centennial value. When&nbsp;new Element is inserted in a Queue then Rear is Incremented by one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3,9,8],"tags":[],"class_list":["post-498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-12th-computer-science","category-bca","category-cbse-12th-computer-science","category-jac-12th-computer-science"],"_links":{"self":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/comments?post=498"}],"version-history":[{"count":1,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/498\/revisions"}],"predecessor-version":[{"id":500,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/posts\/498\/revisions\/500"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/media\/499"}],"wp:attachment":[{"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/media?parent=498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/categories?post=498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aipsacademy.com\/blogs\/wp-json\/wp\/v2\/tags?post=498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}