1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ivahew [28]
2 years ago
6

Once you have your heap structure created, next you must use it as a backing structure to a priority queue. Develop a PriorityQu

eue data structure in a file named PriorityQueue that is backed by a linked heap. Implement the normal methods that accompany a priority queue structure:
SAT
1 answer:
saveliy_v [14]2 years ago
6 0

Using the knowledge in computational language in python it is possible to write a code that Develop a PriorityQueue data structure in a file.

<h3>Writting the code in python:</h3>

<em>import sys</em>

<em>class Node:</em>

<em>def __init__(self,key):</em>

<em>self.left = None</em>

<em>self.right = None</em>

<em>self.val = key</em>

<em>self.parent = None</em>

<em>class MinHeap:</em>

<em>def __init__(self, maxsize):</em>

<em>self.maxsize = maxsize</em>

<em>self.size = 0</em>

<em>self.Heap = Node(-1 * sys.maxsize )</em>

<em>self.FRONT = self.Heap</em>

<em># A utility function to do inorder tree traversal</em>

<em>def isLeaf(self, node):</em>

<em>if node.left == None and node.right == Node:</em>

<em>return True</em>

<em>return False</em>

<em># Function to swap two nodes of the heap</em>

<em>def swap(self, node1, node2):</em>

<em>node1.data, node2.data = node2.data, node1.data</em>

<em># Function to heapify the node at pos</em>

<em>def minHeapify(self, node):</em>

<em># If the node is a non-leaf node and greater</em>

<em># than any of its child</em>

<em>if not self.isLeaf(node):</em>

<em>if (node.data > node.left.data or</em>

<em>node.data > node.right.data):</em>

<em># Swap with the left child and heapify</em>

<em># the left child</em>

<em>if node.left.data < node.right.data:</em>

<em>self.swap(node, node.left)</em>

<em>self.minHeapify(node.left)</em>

<em># Swap with the right child and heapify</em>

<em># the right child</em>

<em>else:</em>

<em>self.swap(node, node.right)</em>

<em>self.minHeapify(node.right)</em>

<em># Function to insert a node into the heap</em>

<em>def insert(self, element):</em>

<em>if self.size >= self.maxsize :</em>

<em>return</em>

<em>self.size+= 1</em>

<em>self.bst_insert(FRONT, element)</em>

<em>current = FRONT</em>

<em>while current.parent != None and current.data < current.parent.data:</em>

<em>self.swap(current, current.parent)</em>

<em>current = current.parent</em>

<em># Function to print the contents of the heap</em>

<em>def Print(self):</em>

<em>self.inorder()</em>

<em># Function to build the min heap using</em>

<em># the minHeapify function</em>

<em>def inorder(self, root):</em>

<em>if root:</em>

<em>inorder(root.left)</em>

<em>print(root.val)</em>

<em>inorder(root.right)</em>

<em>def bst_insert(self, root, node):</em>

<em>if root is None:</em>

<em>root = node</em>

<em>else:</em>

<em>root.next = node</em>

<em>self.FRONT = node</em>

<em># Driver Code</em>

<em>if __name__ == "__main__":</em>

<em>r = Node(50)</em>

<em>bst_insert(r,Node(30))</em>

<em>bst_insert(r,Node(20))</em>

<em>bst_insert(r,Node(40))</em>

<em>bst_insert(r,Node(70))</em>

<em>bst_insert(r,Node(60))</em>

<em>bst_insert(r,Node(80))</em>

<em># Print inoder traversal of the BST</em>

<em>inorder(r)</em>

<em>print('The minHeap is ')</em>

<em>minHeap = MinHeap(15)</em>

<em>minHeap.insert(5)</em>

<em>minHeap.insert(3)</em>

<em>minHeap.insert(17)</em>

<em>minHeap.insert(10)</em>

<em>minHeap.insert(84)</em>

<em>minHeap.insert(19)</em>

<em>minHeap.insert(6)</em>

<em>minHeap.insert(22)</em>

<em>minHeap.insert(9)</em>

<em>minHeap.minHeap()</em>

<em>minHeap.Print()</em>

<em>print("The Min val is " + str(minHeap.remove()))</em>

See more about python at brainly.com/question/13437928

#SPJ1

You might be interested in
Match each gymnosperm to it's correct description
VladimirAG [237]

Answer:

cycads- 3, ginkgoes-4, gnetophytes-2, conifers-1

4 0
3 years ago
Read 2 more answers
Pizza with peparoni or pizza with mustard and pinaple choose wisley ; -)​
professor190 [17]

Answer:

This is an SAT question, so I will be proofreading this for grammar.

The first pizza should be capitalized.

Peparoni is spelled wrong

Pinaple is spelled wrong

wisely is spelled wrong

There should be a period between "pinaple" and "choose"

The first half beginning with "pizza" and ending with "pinaple" is an incomplete sentence.

By the way, I would prefer pineapple.

4 0
2 years ago
Is taking risks a personal decision?
MatroZZZ [7]

Answer:

In my opinion....

Yes, somtetimes it's persoanl depending on the situation/risk in which you have to choose a side from. Example/Explanation is on bottom ↓

Explanation:

Personal risk  - <u>It is anything that exposes you to the risk of losing something of value.</u>

Usually, personal risk is associated with your financial investments and insurance. These investments may be in the stock market, mutual funds, or loans to others.

Risk - <u>It is the potential that a decision will lead to a loss or an undesirable outcome.</u>

In fact, almost any human decision carries some risk, but some decisions are much riskier/more risky than others.

Pls, choose me as brainliest!

7 0
2 years ago
<img src="https://tex.z-dn.net/?f=%20%5C%5C%20%20%5C%5C%20%20%5C%5C%20%20%5C%5C%20%20%5C%5C%20%20%5C%5C%20%20%5C%5C%20%20%5C%5C%
elixir [45]

Answer:

<u>h</u><u>o</u><u>p</u><u>e</u><u> </u><u>t</u><u>h</u><u>i</u><u>s</u><u> </u><u>h</u><u>e</u><u>l</u><u>p</u><u>s</u><u> </u><u>y</u><u>o</u><u>u</u><u>.</u>

<u>Carry</u><u> </u><u>on</u><u> </u><u>learning</u><u>.</u>

5 0
3 years ago
Read 2 more answers
Find the probability that a randomly selected chocolate bar will have less than 200 calories brainly
kozerog [31]

Answer:

the dog

Explanation:

is flying overtake the airplane

7 0
2 years ago
Other questions:
  • Numerous research projects, including the benchmark Framingham Heart Study, demonstrate that taking a vacation can have well-con
    12·2 answers
  • How long does it take for mars to orbit the sun. What is the size of Mars
    13·2 answers
  • Which of the following schools would most likely ask for a letter of recommendation?
    14·2 answers
  • A couple is planning a wedding and they need to decide how many guests on the bride’s side
    5·1 answer
  • Write a problem statement for music and then answer the problem statement.
    7·1 answer
  • Your cousin asks you to tell a lie to her parents.
    13·2 answers
  • Which factors led to the ming dynasty’s decline? choose four answers. Low taxes declining trade rebellion poor leadership increa
    9·1 answer
  • All of the following statements about state governments are true except:.
    9·2 answers
  • The centers of two 15. 0-kilogram spheres are separated by 3. 00 meters. The magnitude of the gravitational force between the tw
    12·1 answer
  • What chivalric value does the Green Knight display in the excerpt? loyalty to his king the morality of fair play bravery despite
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!