40 likes | 203 Views
Lab11. Heap. Goal . Manage a set of "tasks" using a " Heap " data structure implemented as a Min -Priority Queue. The Heap is used to simulate a task manager. The task manger will be responsible for executing the next task and accept a new task.
E N D
Lab11 Heap
Goal • Manage a set of "tasks" using a "Heap" data structure implemented as a Min-Priority Queue. The Heap is used to simulate a task manager. The task manger will be responsible for executing the next task and accept a new task. • Each task has a name and priority number. (e.g., eclipse: 4). The number represents the priority of the task. The smaller the number, the higher the priority of the task. For example, one task with number 1 has higher priority than the one with number 6. • Assume that each task is completed when it is removed from the heap. • Sometimes tasks are added into a heap with very high priority number (low priority). If the priority number remains unchanged while the task is in the heap, it is possible that it will never get executed due to newer tasks being added with a lower priority number (higher priority). Thus, when a task is removed from the heap for execution, all other tasks in the heap have their priority number decremented by 1. There is a restriction that the priority number will never be negative. • when a task is added to the heap, all other tasks currently in the heap remained unmodified.
Example of how the priority number changes. • Task Manager: eclipse:4, javac: 5, notepad: 7 • After executing a task, eclipse:4. (It has minimum priority number). The task manager has the following task: • javac: 4, notepad: 6 • After a new task is accepted into the task manager. Assume the new one is mysql:7. The task manager has the following task. • javac: 4, notepad: 6, mysql:7