The SquareList Data Structure
by Mark Sams


Listing One
void insert(int value)
{
    slNode toAdd = new slNode(value);
    size++;
    if(size == 1)
        head = toAdd;
    else
    {
        slNode temp = findVertList(toAdd);
        putInVertList(temp, toAdd);
    }
    updateMaxDepth();
}


Listing Two
private void shiftLeft(slNode top, int whichOp)
{
    slNode temp = new slNode(top.getValue());
    top.setValue(top.getChild().getValue());
    if(top.getDepth() == 2)
        top.setChild(top);
    else
    {
        top.setChild(top.getChild().getChild());
        top.getChild().setParent(top);
    }
    top.changeDepth(-1);
    slNode left = top.getLeft();
    temp.setParent(left.getBottom());
    left.getBottom().setChild(temp);
    temp.setParent(left.getBottom());
    left.setBottom(temp);
    left.changeDepth(1);
    if(tooDeep(left, whichOp))
        shiftLeft(left, whichOp); 
}   

Listing Three
public int delete(int value)
{
    slNode top = new slNode(findVertList(value));
    slNode toDelete = findInVertList(top, value);
    if(toDelete == null)
        return -1;
    size--;
    // Top node 
    if(toDelete.getParent() == null)
        deleteParentNode(toDelete);
    // Bottom node in sublist
    else if(toDelete.getChild() == toDelete)
        deleteBottomNode(top);
    // Found node in sublist
    else 
        deleteMiddleNode(top, toDelete);
    updatemaxDepth();
    delFixUp ();
    return value;
}

Listing Four
private void delFixUp (slNode theTop)
{
    // Nothing needs to be done.
    if(theTop.getDepth() == maxDepth -1)
        return;
    slNode temp = getFullList();
    if(temp.getValue() > theTop.getValue())
        // This situation should only occur if the list goes from 
       // square + 1 to square
        if((temp == head.getLeft()) && (temp.getDepth() == 1))
        {
            // Move the last node left one list
            putInVertList(temp.getLeft(), temp);
            // Only want to shiftLeft if node is not placed in the short list
            if(theTop != temp.getLeft())
                shiftLeft(temp.getLeft(), ONE);
            // Set the respective pointers
            head.setLeft(temp.getLeft());
            temp.getLeft().setRight(head);
    }
        else shiftLeft(temp, ONE);
    else if(temp.getValue() < theTop.getValue())
        shiftRight(temp, ONE);      
    else ;  // Do nothing.  Depths of lists are appropriate
}






2


