{"id":26991,"date":"2018-01-02T20:32:21","date_gmt":"2018-01-02T15:02:21","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=26991"},"modified":"2018-01-02T20:32:21","modified_gmt":"2018-01-02T15:02:21","slug":"queue-data-structure-deque","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/queue-data-structure-deque\/","title":{"rendered":"Queue-Data Structure-Deque"},"content":{"rendered":"<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Double-ended_queue\" target=\"_blank\" rel=\"noopener noreferrer\">Deque or Double Ended Queue<\/a> is a generalized version of <a href=\"http:\/\/quiz.geeksforgeeks.org\/queue-set-1introduction-and-array-implementation\/\" target=\"_blank\" rel=\"noopener noreferrer\">Queue data structure <\/a>that allows insert and delete at both ends.<span id=\"more-142804\"><\/span><\/p>\n<p><strong>Operations on Deque:<\/strong><br \/>\nMainly the following four basic operations are performed on queue:<\/p>\n<p><strong>insetFront()<\/strong>: Adds an item at the front of Deque.<br \/>\n<strong>insertLast()<\/strong>:Adds an item at the rear of Deque.<br \/>\n<strong>deleteFront()<\/strong>: Deletes an item from front of Deque.<br \/>\n<strong>deleteLast()<\/strong>: Deletes an item from rear of Deque.<\/p>\n<p>In addition to above operations, following operations are also supported<br \/>\n<strong>getFront()<\/strong>: Gets the front item from queue.<br \/>\n<strong>getRear()<\/strong>: Gets the last item from queue.<br \/>\n<strong>isEmpty()<\/strong>: Checks whether Deque is empty or not.<br \/>\n<strong>isFull()<\/strong>: Checks whether Deque is full or not.<\/p>\n[ad type=&#8221;banner&#8221;]\n<p><strong>Applications of Deque:<\/strong><br \/>\nSince Deque supports both stack and queue operations, it can be used as both. The Deque data structure supports clockwise and anticlockwise rotations in O(1) time which can be useful in certain applications.<br \/>\nAlso, the problems where elements need to be removed and or added both ends can be efficiently solved using Deque. For example see <a href=\"http:\/\/www.geeksforgeeks.org\/maximum-of-all-subarrays-of-size-k\/\" target=\"_blank\" rel=\"noopener noreferrer\">Maximum of all subarrays of size k problem.<\/a>, <a href=\"http:\/\/www.geeksforgeeks.org\/0-1-bfs-shortest-path-binary-graph\/\" target=\"_blank\" rel=\"noopener\">0-1 BFS<\/a> and <a href=\"http:\/\/www.geeksforgeeks.org\/find-a-tour-that-visits-all-stations\/\" target=\"_blank\" rel=\"noopener\">Find the first circular tour that visits all petrol pumps<\/a>.<\/p>\n<p>See <a href=\"http:\/\/en.wikipedia.org\/wiki\/Double-ended_queue#Applications\" target=\"_blank\" rel=\"noopener noreferrer\">wiki page <\/a>for another example of A-Steal job scheduling algorithm where Deque is used as deletions operation is required at both ends.<\/p>\n<p><strong>Language Support:<\/strong><br \/>\nC++ STL provides implementation of Deque as <a href=\"http:\/\/www.cplusplus.com\/reference\/deque\/deque\/\" target=\"_blank\" rel=\"noopener noreferrer\">std::deque<\/a> and Java provides <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/util\/Deque.html\" target=\"_blank\" rel=\"noopener noreferrer\">Deque interface<\/a>. See <a href=\"http:\/\/en.wikipedia.org\/wiki\/Double-ended_queue#Language_support\" target=\"_blank\" rel=\"noopener noreferrer\">this <\/a>for more details.<\/p>\n<p><strong>Implementation:<\/strong><br \/>\nA Deque can be implemented either using a <a href=\"http:\/\/quiz.geeksforgeeks.org\/doubly-linked-list\/\" target=\"_blank\" rel=\"noopener noreferrer\">doubly linked list<\/a> or circular array. In both implementation, we can implement all operations in O(1) time. We will soon be discussing C\/C++ implementation of Deque Data structure.<\/p>\n<p><strong><br \/>\n<a href=\"http:\/\/www.geeksforgeeks.org\/implementation-deque-using-circular-array\/\" target=\"_blank\" rel=\"noopener\">Implementation of Deque using circular array<\/a><br \/>\n<\/strong><br \/>\nPlease write comments if you find the above codes\/algorithms incorrect, or find other ways to solve the same problem.<\/p>\n[ad type=&#8221;banner&#8221;]\n","protected":false},"excerpt":{"rendered":"<p>Queue Data Structure Deque &#8211; Data Structure &#8211; Deque or Double Ended Queue is a generalized version of Queue data structure that allows insert and delete.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73012,80124],"tags":[83808,83804,83806,83807,83803,83805,83810,83809,83799,83795,83796,83800,83801,83797,83802,83798],"class_list":["post-26991","post","type-post","status-publish","format-standard","hentry","category-data-structures","category-queue","tag-deque-c","tag-deque-example","tag-deque-geeksforgeeks","tag-deque-implementation","tag-deque-in-c","tag-deque-meaning","tag-deque-pronunciation","tag-deque-vs-vector","tag-dequeue-geeksforgeeks","tag-dequeue-in-data-structure","tag-dequeue-in-data-structure-using-c","tag-double-ended-queue-applications","tag-double-ended-queue-in-data-structure-pdf","tag-double-ended-queue-in-data-structure-with-example","tag-enqueue-in-data-structure","tag-input-restricted-deque"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/26991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=26991"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/26991\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=26991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=26991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=26991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}