


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An explanation of why a dynamic array cannot be used efficiently for a queue or deque due to the o(n) time complexity for adding or removing elements from the beginning or end. It suggests a solution to allow the starting location of the block of elements to 'float' and implement additions or removal from either front or back with constant time complexity. The document also includes the code for the deque structure and functions for adding, retrieving, and removing elements.
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



void _dequeDoubleCapacity (struct deque *d) { EleType * newData; int i = d->start; int j = 0; int s; int currCap = d->capacity; if (currCap <= 0) currCap = 1; newData = malloc(2 * currCap * sizeof(EleType)); assert (newData != 0); for (s = d->size; s > 0; s--) { newData[j++] = d->data[i++]; if (i > d->capacity) i = 0; } free(d->data); d->data = newData; d->capacity = 2 * currCap; d->start = 0; } void dequeFree (struct deque *d) { free(d->data); d->size = 0; d->capacity = 0; }
void dequeRemoveFront (struct deque *d) { } void dequeRemoveBack (struct deque *d) { }