Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey problems are 1 and 2. How do you do these? I have taken the snippets of code needed as well. #define MAXCOUNT 10 typedef

image text in transcribedHey problems are 1 and 2. How do you do these? I have taken the snippets of code needed as well.

image text in transcribedimage text in transcribedimage text in transcribed

#define MAXCOUNT 10 typedef int PQitem; typedef PQItem PQArray[MAXCOUNT); typedef struct int Count; PQArrayItemArray: } PriorityQueue; 1. Revise the function Remove(PQ) defined on lines 78:88 of Program 4.7 to apply the free procedure to recycle storage for the priority queue list node that is removed from the front of the list. 2. Why is PQ->Count decremented (on line 65 of Program 4.8) before the last item in PQ->ItemArray[PQ->Count] is moved into the hole PQ->ItemArray[Maxindex]? Program 4.7 Sorted Linked List Priority Queue Implementation (continued) 651 ....................7 void Insert(PQItem Item, PriorityQueue *PQ) if ( ! Full(PQ)) { PQ->Count++; /* increase PQ's item count and insert PQ->ItemList = Sortedlnsert(Item, PQ->ItemList); /* the new */ /* Item on PQ's ItemList/ PQItem Remove(PriorityQueue *PQ) PQitem temp; if (! Empty(PQ)) { /* result undefined if PQ empty */ temp = PQ->ItemList->Nodeltem; /* otherwise, remove the */ PQ->ItemList = PQ->ItemList->Link; /* highest priority item / PQ->Count -- /* from the front of the list */ return (temp); /* and decrease the item count */ 90 / Program 4.8 Unsorted Array Priority Queue Implementation (continued) 50 PQItem Remove(Priority Queue *PQ) int i; int MaxIndex; PQltem Maxltem; /* i is an index variable that indexes array items */ /MaxIndex is the location of the biggest item / /* Maxitem is the value of the biggest item */ 55 i - if (! Empty(PQ)) { /* result undefined if PQ empty */ Maxitem = PQ->ItemArray[O]; /* initially, let the zeroth item be the */ MaxIndex = 0; /* biggest item found so far */ for (i = 1; i Count; ++i) { /* scan the rest of the items */ if (PQ->ItemAray(0) > Maxitem ) { /* and replace the current */ Maxitem = PQ->ItemArray); /* biggest with any */ MaxIndex = 1; /* bigger ones that are found / - - - 65 PQ->Count --; /* finally, decrease the item count */ PQ->ItemArray[MaxIndex] = PQ->ItemArray[PQ->Count); /* and */ return (Maxitem); * put the last item in the hole vacated by */ /* removing and returning the biggest item */ return ------- I 70 l #define MAXCOUNT 10 typedef int PQitem; typedef PQItem PQArray[MAXCOUNT); typedef struct int Count; PQArrayItemArray: } PriorityQueue; 1. Revise the function Remove(PQ) defined on lines 78:88 of Program 4.7 to apply the free procedure to recycle storage for the priority queue list node that is removed from the front of the list. 2. Why is PQ->Count decremented (on line 65 of Program 4.8) before the last item in PQ->ItemArray[PQ->Count] is moved into the hole PQ->ItemArray[Maxindex]? Program 4.7 Sorted Linked List Priority Queue Implementation (continued) 651 ....................7 void Insert(PQItem Item, PriorityQueue *PQ) if ( ! Full(PQ)) { PQ->Count++; /* increase PQ's item count and insert PQ->ItemList = Sortedlnsert(Item, PQ->ItemList); /* the new */ /* Item on PQ's ItemList/ PQItem Remove(PriorityQueue *PQ) PQitem temp; if (! Empty(PQ)) { /* result undefined if PQ empty */ temp = PQ->ItemList->Nodeltem; /* otherwise, remove the */ PQ->ItemList = PQ->ItemList->Link; /* highest priority item / PQ->Count -- /* from the front of the list */ return (temp); /* and decrease the item count */ 90 / Program 4.8 Unsorted Array Priority Queue Implementation (continued) 50 PQItem Remove(Priority Queue *PQ) int i; int MaxIndex; PQltem Maxltem; /* i is an index variable that indexes array items */ /MaxIndex is the location of the biggest item / /* Maxitem is the value of the biggest item */ 55 i - if (! Empty(PQ)) { /* result undefined if PQ empty */ Maxitem = PQ->ItemArray[O]; /* initially, let the zeroth item be the */ MaxIndex = 0; /* biggest item found so far */ for (i = 1; i Count; ++i) { /* scan the rest of the items */ if (PQ->ItemAray(0) > Maxitem ) { /* and replace the current */ Maxitem = PQ->ItemArray); /* biggest with any */ MaxIndex = 1; /* bigger ones that are found / - - - 65 PQ->Count --; /* finally, decrease the item count */ PQ->ItemArray[MaxIndex] = PQ->ItemArray[PQ->Count); /* and */ return (Maxitem); * put the last item in the hole vacated by */ /* removing and returning the biggest item */ return ------- I 70 l

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions