Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS2123 Data Structures Recall the stack ADT and its improved implementation using dynamic array with initial size of 100 elements. It was doubling the size

image text in transcribed

CS2123 Data Structures Recall the stack ADT and its improved implementation using dynamic array with initial size of 100 elements. It was doubling the size of the dynamic array by calling Expand(stack) in Push(stack, element) function when the current stack is full Suppose we want to implement a similar (but an opposite) function Shrink(stack) that will be called in Pop(stack) when the number of elements in stack is less than the quarter of the current size of the array and the size of the array is larger than 200. Below are some of the original declarations in stack.h and stack.c files, and the modified Pop(stack) function. / stack. h / | #define Initia!StackSize 100 ***improved stack.c**** struct stackCDT typedef double stackElementT *elements; int count; int size; stackElementT; typedef struct stackCDT *stackADT stackElementT Pop(stackADT stack) * exported functionsif (StackIsEmpty (stack)) Error("Pop of an empty stack"); if(stack->countsize 200) Shrink(stack) return (stack->elements[-stack->count]; So, you will just implement Shrink(stackADT stack) function, which should allocate a new array with the half size of the current array, copy the existing elements from old array into nevw array, free the old array, and update the necessary fields in the stackCDT pointed by stack. static void Shrink (stackADT stack)

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago