{"id":14064,"date":"2020-03-30T18:47:29","date_gmt":"2020-03-31T01:47:29","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=14064"},"modified":"2023-12-01T02:35:59","modified_gmt":"2023-12-01T10:35:59","slug":"c-plus-plus-priority-queue","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/","title":{"rendered":"Priority Queue C++"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How to Use Priority Queue in C++ <\/h2>\n\n\n\n<p>In programming, queues are used to create data structures that store values in a first-in, first-out order.<\/p>\n\n\n\n<p>When you\u2019re coding in C++, you may want to create a queue that processes the element that has the highest priority. This would be instead of the element that comes before that item in the queue, which is the order used in regular queues.<\/p>\n\n\n\n<p>That\u2019s where the C++ priority queue comes in. This tutorial will discuss, with reference to examples, the basics of priority queues in C++, how to create a priority queue, and how to manipulate the data stored in a priority queue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ Priority Queues<\/h2>\n\n\n\n<p>Queues are a type data structure which follow a first-in, first-out order. This means that the first item inserted into a queue is the first one that will be removed from the queue.<\/p>\n\n\n\n<p>Let\u2019s say you are waiting in line at a checkout in a supermarket. The first person who shows up to the line should be the first person served, because they have been waiting the longest. This is exactly how a queue works in programming.<\/p>\n\n\n\n<p>However, there is another type of queue used in coding called a priority queue. Priority queues serve elements with the highest priority first, then serve elements with lower priorities. A real-world example of a priority queue would be a waitlist for a club which has a VIP list. If you\u2019re a VIP, you should be admitted before everyone else who is waiting in line.<\/p>\n\n\n\n<p>So, with a priority queue, you can skip the first-in, first-out structure, and instead process an element with the highest priority.<\/p>\n\n\n\n<p>For instance, if you had a priority queue that contains the values 92, 1, and 102\u2014which were inserted in that order\u2014102 would be processed first, because it is the largest number and therefore has the highest priority. Here\u2019s how the data would be stored in this priority queue:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>Queue Order<\/strong><\/td><\/tr><tr><td>102<\/td><\/tr><tr><td>92<\/td><\/tr><tr><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>As you can see, 102 is at the top of our queue, even though we added it in last. That\u2019s because our elements in the priority queue are stored based on their size (or priority).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Priority Queue<\/h2>\n\n\n\n<p>The C++ priority queue is contained within the C++ standard library. This means that, when we create a priority queue, we are referencing the standard library.<\/p>\n\n\n\n<p>In addition, we need to import the queue class before we start working with a priority queue. Here\u2019s the code we can use to import the queue class:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;queue&gt;<\/pre><\/div>\n\n\n\n<p>Now that we\u2019ve imported the queue class into our code, we can start creating priority queues. Here\u2019s the syntax for creating a priority queue in C++: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>priority_queue &lt;dataType&gt; queueName;<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down this syntax into its main components:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>priority_queue<\/strong> tells our program to create a priority queue.<\/li>\n\n\n\n<li><strong>dataType<\/strong> is the type of data that will be stored in our priority queue.<\/li>\n\n\n\n<li><strong>queueName<\/strong> is the name assigned to our queue.<\/li>\n<\/ul>\n\n\n\n<p>Suppose we wanted to create a priority queue which stores the ticket numbers of people who are on a waitlist to enter an exclusive club.<\/p>\n\n\n\n<p>Standard tickets, which give people no priority when entering the club, have a ticket number between 1 and 100. VIP tickets, which allow people to get in before standard ticket holders, have a ticket number between 100 and 200. The higher the customer\u2019s ticket number, the earlier they should be able to enter the club.<\/p>\n\n\n\n<p>Here\u2019s the code we could use to create a priority queue to store these ticket numbers:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>priority_queue &lt;int&gt; tickets;<\/pre><\/div>\n\n\n\n<p>In our example, we have declared a priority queue called tickets which stores integers. In this priority queue, the values with the highest number will be processed first in the queue. So, ticket holder #100 will be processed before ticket holder #99, for example.<\/p>\n\n\n\n<p>Each element stored in a priority queue is called an item.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add Item to Priority Queue<\/h2>\n\n\n\n<p>The priority queue <code>push()<\/code> method is used to add an item to a priority queue. push() accepts one parameter, which is the value you want to add to your queue.<\/p>\n\n\n\n<p>Suppose we have just sold a new VIP ticket and we want to add them to our priority queue. Our ticket queue already contains the values for ticket holders 50, 75, and 149.<\/p>\n\n\n\n<p>This VIP ticket has the ticket number 120, which means that they will be ahead of all standard ticket holders, but they will not be ahead of people who have a higher ticket number than them. We could use the following code to add them to a priority queue:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\n#include &lt;queue&gt;\nusing namespace std;\nint main() {\n\tpriority_queue &lt;int&gt; tickets;\n\ttickets.push(50);\n\ttickets.push(75);\n\ttickets.push(149);\n\ttickets.push(120);\n\tcout &lt;&lt; tickets.top();\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>149<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down our code. First, we have initialized a priority queue called tickets which stores integer values. Then we used <code>push()<\/code> to add 50, 75, and 149 to our queue, which are tickets that have already been sold.<\/p>\n\n\n\n<p>We then used <code>push()<\/code> to add our new ticket, #120, to the tickets queue. Finally, we used <code>top()<\/code> to retrieve the item at the top of our queue (the item with the highest priority).<\/p>\n\n\n\n<p>In a traditional queue &#8212; that uses the first-in, first-out structure &#8212; the <code>top()<\/code> method would return 50, which was the first item in the queue. However, because we have declared a priority queue, our program returns 149, which is the highest value in our queue. For reference, here is how the values in our queue are stored:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>Queue Order<\/strong><\/td><\/tr><tr><td>149<\/td><\/tr><tr><td>120<\/td><\/tr><tr><td>75<\/td><\/tr><tr><td>50<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This table illustrates that the items in our queue are stored based on their value\u2014the highest value is at the top of the queue\u2014rather than the order in which they were inserted into our queue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Retrieve Item from Priority Queue<\/h2>\n\n\n\n<p>When you\u2019re working with a priority queue, you may want to retrieve the largest value in the queue. That\u2019s where the <code>top()<\/code> method comes in.<\/p>\n\n\n\n<p>Suppose you were about to admit someone into the club and you want to know which ticket holder is next in line. You could use the following code to find out the highest ticket number which exists in the queue:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\n#include &lt;queue&gt;\nusing namespace std;\nint main() {\n\tpriority_queue &lt;int&gt; tickets;\n\ttickets.push(50);\n\ttickets.push(75);\n\ttickets.push(149);\n\ttickets.push(120);\n\tcout &lt;&lt; tickets.top();\n}<\/pre><\/div>\n\n\n\n<p>This example is the same one we used to illustrate adding an item to a queue, and the example returns: 149. As you can see, <code>top()<\/code> retrieved the item at the top of our queue, which is the highest value in our queue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Remove Item from Priority Queue<\/h2>\n\n\n\n<p>The priority queue <code>pop()<\/code> function is used to remove an item from a C++ priority queue.<\/p>\n\n\n\n<p><code>pop()<\/code> removes the largest item from a queue, and then places the second largest item at the beginning of the queue. <code>pop()<\/code> accepts no parameters, as it removes the largest item from the queue instead of a specific item.<\/p>\n\n\n\n<p>Let\u2019s return to our club example from earlier. Suppose that we are starting to let people into the club for the party. We want to remove the person with the highest priority from our queue, who has just been admitted, so that we are ready to admit new people into the club when a space opens up.<\/p>\n\n\n\n<p>We could use the following code to remove the ticket number from our queue with the highest priority:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\n#include &lt;queue&gt;\nint main() {\n\tpriority_queue &lt;int&gt; tickets;\n\ttickets.push(50);\n\ttickets.push(75);\n\ttickets.push(149);\n\ttickets.push(120);\n\ttickets.pop();\n\tcout &lt;&lt; tickets.top();\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>120<\/pre><\/div>\n\n\n\n<p>In our example, we first declare a priority queue called tickets, which stores integer values. Then we add the values 50, 75, 149, and 120 to our queue.<\/p>\n\n\n\n<p>We then use the <code>pop()<\/code> method to remove the item at the top of our priority queue, which is 149 in this case (remember, priority queues prioritize the highest value). Then, we print the item which is at the top of the queue using <code>top()<\/code> after <code>pop()<\/code> has been run.<\/p>\n\n\n\n<p>So, in this case, 149 is removed. This means our program prints out 120 when the <code>top()<\/code> method is executed. 120 is the second-highest value in our queue and becomes the highest once 149 is removed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Print a Priority Queue<\/h2>\n\n\n\n<p>The priority queue method does not include any functions that can be used to print the contents of a queue. However, we can use a standard for loop and the <code>top()<\/code>, <code>empty()<\/code>, and <code>pop()<\/code> methods to iterate through every item in a queue and print each one to the console.<\/p>\n\n\n\n<p>Suppose we want to create a list of everyone who is on the waitlist to enter our club. We could do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\n#include &lt;queue&gt;\nint main() {\n\tpriority_queue &lt;int&gt; tickets;\n\ttickets.push(50);\n\ttickets.push(75);\n\ttickets.push(149);\n\ttickets.push(120);\n\tpriority_queue &lt;int&gt; new_queue = tickets;\n\twhile (!new_queue.empty()) {\n\t\tcout &lt;&lt; new_queue.top() &lt;&lt; \"\\n\";\n\t\tnew_queue.pop();\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>149\n120\n75\n50<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down our code. First, we declare a priority queue called tickets, and we use the <code>push()<\/code> method to add the values 50, 75, 149, and 20 to our priority queue.<\/p>\n\n\n\n<p>Next, we declare a new priority queue called new_queue and assign it the same values that are stored in our tickets queue. We do this because we are going to remove items from this queue later in our code, and we don\u2019t want to affect our initial queue.<\/p>\n\n\n\n<p>On the next line, we initialize a while loop. The while loop evaluates the statement <code>!new_queue.empty()<\/code>, which means that it will run until the queue new_queue is empty.<\/p>\n\n\n\n<p>In the body of our while loop, we use <code>top()<\/code> to retrieve the item at the top of our queue, then we print it to the console, followed by a new line character (represented by <code>\\n<\/code>). We then use <code>pop()<\/code> to remove the item at the top of our queue.<\/p>\n\n\n\n<p>This means that, next time the while loop runs, we can get the next-highest item and print it to the console, before we remove that item and repeat the process until the queue is empty.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Other Priority Queue Methods<\/h2>\n\n\n\n<p>The priority queue includes a few additional methods which can be used to interact with the data type. Here is a reference table that lists these methods:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td><strong>Method<\/strong><\/td><td><strong>Description<\/strong><\/td><\/tr><tr><td>empty()<\/td><td>Checks whether a priority queue is empty. empty() returns true if a queue is empty and false if a queue() contains one or more items.<\/td><\/tr><tr><td>size()<\/td><td>Returns the number of elements in a queue.<\/td><\/tr><tr><td>swap()<\/td><td>Swaps the content between two priority queues of the same size and type.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The priority queue is used to create a queue which stores values based on their size. This means that the highest value is stored at the top of a priority queue, and subsequent items are stored in descending order.<\/p>\n\n\n\n<p>This tutorial discussed, with reference to examples, the basics of priority queues, how to create a priority queue, and how to add, remove, and retrieve items from a priority queue. Now you have the information you need to start using priority queues in C++ like a pro!<\/p>\n","protected":false},"excerpt":{"rendered":"How to Use Priority Queue in C++ In programming, queues are used to create data structures that store values in a first-in, first-out order. When you\u2019re coding in C++, you may want to create a queue that processes the element that has the highest priority. This would be instead of the element that comes before&hellip;","protected":false},"author":240,"featured_media":14065,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17291],"tags":[],"class_list":{"0":"post-14064","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-c-plus-plus"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"C++","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Priority Queue C++ | Career Karma<\/title>\n<meta name=\"description\" content=\"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Priority Queue C++\" \/>\n<meta property=\"og:description\" content=\"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-31T01:47:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:35:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Priority Queue C++\",\"datePublished\":\"2020-03-31T01:47:29+00:00\",\"dateModified\":\"2023-12-01T10:35:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/\"},\"wordCount\":1701,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/woman-smiling-while-using-laptop-3769717.jpg\",\"articleSection\":[\"C++ Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/\",\"name\":\"Priority Queue C++ | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/woman-smiling-while-using-laptop-3769717.jpg\",\"datePublished\":\"2020-03-31T01:47:29+00:00\",\"dateModified\":\"2023-12-01T10:35:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/woman-smiling-while-using-laptop-3769717.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/woman-smiling-while-using-laptop-3769717.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus-priority-queue\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Programming\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/c-plus-plus\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Priority Queue C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Priority Queue C++ | Career Karma","description":"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.","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:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/","og_locale":"en_US","og_type":"article","og_title":"Priority Queue C++","og_description":"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.","og_url":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-03-31T01:47:29+00:00","article_modified_time":"2023-12-01T10:35:59+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Priority Queue C++","datePublished":"2020-03-31T01:47:29+00:00","dateModified":"2023-12-01T10:35:59+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/"},"wordCount":1701,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg","articleSection":["C++ Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/","url":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/","name":"Priority Queue C++ | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg","datePublished":"2020-03-31T01:47:29+00:00","dateModified":"2023-12-01T10:35:59+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Priority queues store data in order based on their priority. On Career Karma, learn how to use priority queues in your C++ code.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/woman-smiling-while-using-laptop-3769717.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-priority-queue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"C++ Programming","item":"https:\/\/careerkarma.com\/blog\/c-plus-plus\/"},{"@type":"ListItem","position":3,"name":"Priority Queue C++"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/14064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=14064"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/14064\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/14065"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=14064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=14064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=14064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}