Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 Step 3: push and pull integers to the list (40 marks) In this section, you will write three functions, pushInt, to store a digit

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

3 Step 3: push and pull integers to the list (40 marks) In this section, you will write three functions, pushInt, to store a digit in the list, pullint, to remove a digit from the list, and clearList, which calls pullint until the list is completely free, deallocate the free nodes, and call freeList to free the head and the tail of the list. pushInt will check that the list has a nonempty free space, i.e. if length is not zero, and, if so, store a new digit in it. If the free space is empty, pushInt will call allocateBlock to increase its size and then perform the required push operation. pullint will 6 remove a digit from one side of the list and then check if the size of the free space is larger than BLOCKSIZE. In that case, pullint should call deAllocateBlock to deallocate BLOCKSIZE free nodes. - Declare pushint as void pushint (struct list pList, int *counter, int i); 1 where pList and counter are interpreted as in the previous section and i is an integer from 0 to 9 . pushint should - call allocateBlock, with BLOCKSIZE as a third argument, if there are no free nodes in the gap, - check if i is odd or even, - if i is odd, store it on the first available node on the right of the head-side stack, i.e. on the node on the right of the node pointed by pList->left, and, - if i is even, store it on the first available node on the left of the tail-side stack, i.e. on the node on the left of the node pointed by pList->right. - Declare pullint as void pullint(struct list *pList, int *counter, int i); 1 where pList, counter, and i are interpreted as in pushInt. In this case, i is used to decide on what side of the list you perform the pull operation, i.e. to decide whether you remove the (odd) digit in the node pointed by pList->left or the (even) digit in the node pointed by pList->right. pullint should - check if i is odd or even, - if i is odd, check that pList->left = pList->head, i.e. there is at least one odd integer in the list, and, if so, * replace the digit in the node pointed by pList->left with 1, * increase pList->length by one, - if i is even, check that pList->right = pList->tail, i.e. there is at least one even integer in the list, and, if so, * replace the digit in the node pointed by pList->right with 1, * move pList->right to pList->right->next, and * increase pList->length by one, - check if pList > length > BLOCKSIZE and, if so, call deAllocateBlock to remove BLOCKSIZE free nodes from the free space. - Declare clearList as void clearlist (struct list pList, int counter) where pList and counter are interpreted as in pushint and pullint. clearList should - remove all digits in the head-side stack by calling pullint with i=1 until pList->left points to the head of the list, - remove all digits in the tail-side stack by calling pullint with i=0 until pList->right points to the tail of the list, - remove all free nodes by calling deAllocateBlock with pList->length as the third argument, and - free the list by calling freeList. py step2. c into a new file, step3.c, and replace main with Listing 4: Pushing and pulling Compile the code and check that the output is the same as in the following example. Examaple. If you set BLOCKSIZE to 2, the output should be and setting BLOCKSIZE to 1 gives 8

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

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions