Question: 2 Step 2: allocate free nodes (20 marks) In this section, you will make the program allocate extra free space. Free nodes will be added

 2 Step 2: allocate free nodes (20 marks) In this section,

you will make the program allocate extra free space. Free nodes will

2 Step 2: allocate free nodes (20 marks) In this section, you will make the program allocate extra free space. Free nodes will be added to the list in blocks of BLOCKSIZE nodes, where BLOCKSIZE is a macro defined as #define BLOCKSIZE 5 Your task is to write a function declared as void allocateBlock (struct list plist, int *counter) that adds BLOCKSIZE nodes on the right of the node pointed by pList->left. The function should consist of a loop of BLOCKSIZE iterations where, at each iteration, you allocate a new object of type struct node with allocator link the new node to the existing ones so that the doubly-linked structure of the list is preserved set i of the new node to - 1 increase pList->length by one To preserve the doubly-linked structure of the list at every step, you need to . let prev of the new node be a pointer to the node pointed by pList->left let next of the new node be a pointer to the node pointed by pList->left->next . let prev of the node pointed by plist->left->next be a pointer to the new node let next of the node pointed by pList->left be a pointer to the new node To get an intuition of what the function is supposed to do, draw a simple cartoon of the node-insertion process. Copy step1.c into a new file, call it step2.c, and replace main with int main() { int counter = 0; struct list myList; printf("initialising the list "); initialiseList(&myList, &counter); printList (EmyList, &counter); printf ("allocating $d free nodes ", BLOCKSIZE); allocateBlock (EmyList, Ecounter); printList (&myList, 6counter); printf("freeing $d free nodes ", BLOCKSIZE); deAllocateBlock (EmyList, scounter); printList (EmyList, &counter); print("Ereeing head and tail ... "); removeList (&myList. counter); printList (AmyList, &counter); } Code 3: Free node allocation 1 2 3 4 6 ... 7 5 10 11 12 13 11 15 IG 17 6 Check that the file contains all required headers, macros, structure definitions and function declarations before main and all functions definitions after it. The code of de AllocateBlock, printList, and removeList are given in Appendix A. Example If you set BLOCKSIZE to 5, the output should be initialising the list ... | 0 | 10 | counter - 2 allocating 5 free nodes ... 101 1-1 1-1 | 1-1 1-1 1-1 1011 counter - 7 freeing 5 free nodes ... 101 101 counter - 2 freeing head and tail ... counter - 0 2 Step 2: allocate free nodes (20 marks) In this section, you will make the program allocate extra free space. Free nodes will be added to the list in blocks of BLOCKSIZE nodes, where BLOCKSIZE is a macro defined as #define BLOCKSIZE 5 Your task is to write a function declared as void allocateBlock (struct list plist, int *counter) that adds BLOCKSIZE nodes on the right of the node pointed by pList->left. The function should consist of a loop of BLOCKSIZE iterations where, at each iteration, you allocate a new object of type struct node with allocator link the new node to the existing ones so that the doubly-linked structure of the list is preserved set i of the new node to - 1 increase pList->length by one To preserve the doubly-linked structure of the list at every step, you need to . let prev of the new node be a pointer to the node pointed by pList->left let next of the new node be a pointer to the node pointed by pList->left->next . let prev of the node pointed by plist->left->next be a pointer to the new node let next of the node pointed by pList->left be a pointer to the new node To get an intuition of what the function is supposed to do, draw a simple cartoon of the node-insertion process. Copy step1.c into a new file, call it step2.c, and replace main with int main() { int counter = 0; struct list myList; printf("initialising the list "); initialiseList(&myList, &counter); printList (EmyList, &counter); printf ("allocating $d free nodes ", BLOCKSIZE); allocateBlock (EmyList, Ecounter); printList (&myList, 6counter); printf("freeing $d free nodes ", BLOCKSIZE); deAllocateBlock (EmyList, scounter); printList (EmyList, &counter); print("Ereeing head and tail ... "); removeList (&myList. counter); printList (AmyList, &counter); } Code 3: Free node allocation 1 2 3 4 6 ... 7 5 10 11 12 13 11 15 IG 17 6 Check that the file contains all required headers, macros, structure definitions and function declarations before main and all functions definitions after it. The code of de AllocateBlock, printList, and removeList are given in Appendix A. Example If you set BLOCKSIZE to 5, the output should be initialising the list ... | 0 | 10 | counter - 2 allocating 5 free nodes ... 101 1-1 1-1 | 1-1 1-1 1-1 1011 counter - 7 freeing 5 free nodes ... 101 101 counter - 2 freeing head and tail ... counter - 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!