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]
1 year 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]1 year 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
Use the drop-down menus to complete the statements. At the age of eighteen, all male citizens are required to. A citizen receive
Dafna11 [192]

(At the age of eighteen, all male citizens are required to-) register with Selective Service.-

(A citizen receives a summons from a US court to report for-). Jury service-

(The three most common types of taxes that citizens must pay are income, sales, and taxes.) Federal income, payroll, Social security and medicare and state income taxes.

8 0
3 years ago
Read 2 more answers
A 900-kg car traveling east at 15. 0 m/s suddenly collides with a 750-kg car traveling north at 20. 0 m/s. The cars stick togeth
dexar [7]

By conservation of momentum,

(900 kg) (15.0 m/s) i + (750 kg) (20.0 m/s) j = (900 kg + 750 kg) v

where v is the velocity vector of the combined cars. Solve for v :

(13,500 i + 15,000 j) kg•m/s = (1650 kg) v

v ≈ (8.18 i + 9.09 j) m/s

Then the direction of v relative to East is θ such that

tan(θ) ≈ 9.09/8.18   ⇒   θ ≈ 48.0°

so the wreckages would move at approximately 48.0° north of east.

4 0
2 years ago
Relationship break up because of a number of reasons name and explain two factors.
Valentin [98]

Answer:

1. misunderstanding.

2. lossing interest.

7 0
2 years ago
In what way was youth activism during the civil rights era the same as it is
olga55 [171]

Answer:

D

Explanation:

6 0
3 years ago
Read 2 more answers
Which statements regarding multiple referral are true
Len [333]

The statements regarding multiple referrals that are true are:

  • Multiple referrals increase the power of the leadership.
  • Multiple referrals is more common in the U.S. House than the U.S. Senate.
  • Complex bills that concern many different issues may be assigned to different standing committees.

<h3>What is Multiple Referral?</h3>

This refers to the process where a proposed bill in the legislature is sent for a second reading.

Hence, we can see that in the United States legislature, multiple referrals help to increase the power base of the leadership and are more common in the U.S. House than in the U.S. Senate.

Read more about US Senate here:

brainly.com/question/277056

#SPJ1

3 0
2 years ago
Other questions:
  • In your own words, explain why underlining important words in a test question is important.
    11·2 answers
  • Why would you want to use note cards rather than several pages of paper when giving a speech? which of these answers best repres
    11·1 answer
  • The Occupational Safety and Health Administration requires employers to provide fall protection to construction workers who are
    10·1 answer
  • What do students typically need to take a standardized test
    9·2 answers
  • What is the answer to 45+67 - 8 times 6 ? Plus im bored if you wanna talk
    10·2 answers
  • Which of the following people outside of your high school would be appropriate to ask for a letter of recommendation?
    5·1 answer
  • Suppose that the starting salaries for faculty at Super University follow a normal distribution with mean of $80,000 and standar
    15·1 answer
  • Answer the following question in 3-4 complete sentences. Define the terms, symbol and logo. Think about how they are similar and
    8·2 answers
  • Which set of lines in this excerpt from "easter, 1816" by w. b. yeats suggests that the speaker had only a limited acquaintance
    6·1 answer
  • In the diagram, curves 1, 2, and 3 represent the total, marginal, and average product curves respectively. total, average, and m
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!