Presentation is loading. Please wait.

Presentation is loading. Please wait.

PS3-Slides typedef struct ProcessTag{ int id; int size; int time; int importance; int priority; } PrintJob; Priority is - say - a function of size, time.

Similar presentations


Presentation on theme: "PS3-Slides typedef struct ProcessTag{ int id; int size; int time; int importance; int priority; } PrintJob; Priority is - say - a function of size, time."— Presentation transcript:

1 PS3-Slides typedef struct ProcessTag{ int id; int size; int time; int importance; int priority; } PrintJob; Priority is - say - a function of size, time and importance Process Queue Insert Process into Process Queue Remove Process of highest priority

2 PS3-Slides Using an Abstract Data Type Application program Module Implementation Module Interface Specification Process Manager Priority Queue Abstract Data Type

3 PS3-Slides Priority Queue Abstract Data Type Interface Specification 1) Application must define PQItem. typedef Process PQItem; 2) Functions the Priority Queue needs from the Application: int Order(Process x, Process y); Process NullItem(void); void CopyItem(Process *newjob, Process oldjob);

4 PS3-Slides Priority Queue Abstract Data Type Interface Specification 3) Public Functions Available to Application from Priority Queue: void PQInitialization(PriorityQueue *); bool PQEmpty(PriorityQueue *); bool PQFull(PriorityQueue *); int PQSize(PriorityQueue *); void PQInsert(PQItem, PriorityQueue *); PQItem PQRemove(PriorityQueue *);

5 PS3-Slides Communicating Between Application Program and Module /* Application Program File */ #include … #include "Application.h" /*contains definitions of the items and structures used in the application program and prototypes of application functions the module needs */ #include "ModuleInterface.h" /* contains public data and function prototypes in the module */ void ApplicationFunction1(void) { … } … int main(void){ … }

6 PS3-Slides Communicating Between Application Program and Module /* Module File */ #include … #include "Application.h" /* see previous comments */ #include "ModuleInterface.h" /* see previous comments */ void ModuleFunction1(void){ … } …

7 PS3-Slides Application program Module Implementation 1 Module Interface Specification Application program Module Implementation 2 Module Interface Specification These are identical These are different Changing Module Implementations

8 PS3-Slides Priority Queue Implemented with Sorted Linked List Count ItemList PQItem Link PQItem Link PQItem Link The Priority Queue typedef struct PQNodeTag { /* Node */ PQItem NodeItem; struct PQNodeTag *Link; } PQListNode; typedef struct { /* The queue */ int Count; PQListNode *ItemList; } PriorityQueue;

9 PS3-Slides Priority Queue Implemented with Unsorted Array Count ItemArray The Priority Queue PQItem 0 1 2 3 Count-1 MAXCOUNT-1 typedef PQItem PQArray[MAXCOUNT] typedef struct{ int Count; PQArray ItemArray; } PriorityQueue; PQItems in order of INSERTION.

10 Process Management using a Priority Queue This program uses a Priority Queue to manage processes. The list can hold a maximum of 50 jobs. Using Sorted Linked-list Implementation of Priority Queue. MAKE SURE YOUR APPLICATION PROGRAM USES '#include PQImpl1.h'. Use the H command anytime to list valid commands. Valid commands are: A - Add a process to the Priority Queue R - Remove the highest priority process from the Priority Queue C - Show the number of processes in the Priority Queue H - List valid commands Q - Quit Command> a New process job: Size: 4 Time: 12 Importance (insignificant=0, average=1, or urgent=2): 1 Job id = 1 size = 4 time = 12 importance = 1 priority = 4 PS3-Slides

11 Command> a New process: Size: 2 Time: 8 Importance (insignificant=0, average=1, or urgent=2): 1 Job id = 2 size = 2 time = 8 importance = 1 priority = 2 Command> a New process: Size: 7 Time: 22 Importance (insignificant=0, average=1, or urgent=2): 1 Job id = 3 size = 7 time = 22 importance = 1 priority = 7 Command> c Number of jobs in Process Queue is 3 Command> r Highest priority process removed: Job id = 3 size = 7 time = 22 importance = 1 priority = 7 Command>


Download ppt "PS3-Slides typedef struct ProcessTag{ int id; int size; int time; int importance; int priority; } PrintJob; Priority is - say - a function of size, time."

Similar presentations


Ads by Google