I think 1 and 2 are sort of separate, but you could concievably have a hybrid version of the two - the #2 concept is derived from laserlights comments (maybe misconstrued, but I think that's what laserlight implied).
And in 2, you wouldn't (as I see it) split a block as such, you would just make a link. Say we have this:
Code:
struct dqBlock
{
int first, last;
int blocksize;
T *data; // T is the data type stores.
struct dqBlock *next;
// Other stuff may be here too.
};
Currently we have ONE block with ABCDMNOP
We want to insert E in order:
Code:
// Pseudo C++ code:
insertBlock(dqBlock ¤t, T newData, int insertPos)
dqBlock p = new dqBlock;
dqBlock n = new dqBlock;
p->first = 0;
p->last = current.last - insertPos;
p->blocksize = current.blocksize - insertPos;
current.last = insertPos-1;
current.blocksize = insertPos;
current.next = n;
n->first = BLOCKSIZE/2;
n->last = BLOCKSIZE/2+1;
n->next = p;
n->data = new T [BLOCKSIZE];
n->blockSize = BLOCKSIZE;
n->data[BLOCKSIZE/2] = newData;
This is just to give you an idea.
And as I said, it's probably not a good idea to ONLY do this inside a deque implementation - you will potentially end up with a linked list with one item per node - not a good situation for performance reasons, and you should probably use a list if that's what you actually want.
Also, I have not looked at the specifications for deque, nor have I looked inside anyones implementation to see what they actual internal data structure is.
--
Mats