/* Inserts a new SLLNode into an Array of available slots The TOP and BOTTOM slots already exist with INT_MAX and -INT_MAX as values. There are no special case top and bottom inserts. */ #include "LinkList.h" void SLLInsert(struct SLLNode SLList[],int value, int NextAvailable){ struct SLLNode PreviousNode, CurrentNode; int i=0; /* Descending to find insertion point */ CurrentNode = SLList[0]; while(value < CurrentNode.value && CurrentNode.down!=NULL){ PreviousNode = CurrentNode; CurrentNode = *(PreviousNode.down); }; /* If CurrentNode.down==NULL then insert NULL pointer in SLList[NextAvailable] and fix CurrentNode pointer. Otherwise insert between Previous and Current Nodes. */ if(CurrentNode.down==NULL){ /* Setting the new Node as last */ SLList[NextAvailable].value = value; SLList[NextAvailable].current = &SLList[NextAvailable]; SLList[NextAvailable].down = NULL; /* setting the Current Node pointer to the new last node */ (*(CurrentNode.current)).down = SLList[NextAvailable].current; } else { /* Setting the new Node to point at NextNode */ SLList[NextAvailable].value = value; SLList[NextAvailable].current = &SLList[NextAvailable];; SLList[NextAvailable].down = CurrentNode.down; /* setting the Current Node pointer to the new node */ SLList[NextAvailable].down = &CurrentNode; }; };