Beispiel #1
0
EdgeNode *insertOrderedLL(EdgeNode **pHead, Edge value)
{
    EdgeNode *pNew, *pFind, *pPrecedes;
    // see if it already exists
    pFind = searchLL(*pHead, value.iVertex, &pPrecedes);
    if (pFind != NULL)
        return pFind;

    // doesn't already exist.  Allocate a node and insert.
    pNew = allocateEdgeNode(value);

    // Check for inserting at the beginning of the list
    // this will also handle when the list is empty
    if (pPrecedes == NULL)
    {
        pNew->pNextEdge = *pHead;
        *pHead = pNew;
    }
    else
    {
        pNew->pNextEdge = pPrecedes->pNextEdge;
        pPrecedes->pNextEdge = pNew;
    }
    return pNew;
}
Beispiel #2
0
void testLL() {
    node* head = NULL;
    int vals[20] = {2,2,2,4,4,2,6,2,4,4,31,37,9,6,4,5,2,2,2,4};
    // Initialize:
    int i;
    for (i=0; i < 20; i++) {
        insertNode(&head, vals[i]);
    }
    
    // Get stats
    printf("Size: %d, Index of 6: %d\n", countNodes(head), searchLL(head, 6));
    printLL(head);
    removeNode(&head, 2);
    printLL(head);
    removeNode(&head, 4);
    printLL(head);
    printf("Size: %d, Index of 6: %d\n", countNodes(head), searchLL(head, 6));
}
Beispiel #3
0
/************************ insertOrderedLL **************************************
NodeLL *insertOrderedLL(LinkedList list, Event value)
Purpose:
	Inserts an element in the list in the correct ordered position.
Parameters:
	O	LinkedList list		The list to insert the event in.
	I	Event value			The Event to be inserted in the list.
Returns:
	Functionally:
		A pointer to the newly created node containing the element.
	list parm - the list with the new element added.
Notes: 
	Adapted for a LinkedList with Header Node.
*******************************************************************************/
NodeLL *insertOrderedLL(LinkedList list, Event value)
{
	NodeLL *pNew, *pPrecedes;
	searchLL(list, value.iTime, &pPrecedes);
	pNew = allocateNodeLL(list, value);
	pNew->pNext = pPrecedes->pNext;
	pPrecedes->pNext = pNew;
	return pNew;
}
NodeLL *insertOrderedLL(LinkedList list, Student value)
{
  NodeLL *pNew, *pFind, *pPrecedes;
  // see if it already exists
  pFind = searchLL(list, value.szAbc123Id, &pPrecedes);
  if (pFind != NULL)
    return pFind;
  
  // doesn't already exist.  Allocate a node and insert.
  pNew = allocateNode(list, value);
  
  // Check for inserting at the beginning of the list
  // this will also handle when the list is empty
  if (pPrecedes == NULL) {
    pNew->pNext = list->pHead;
    list->pHead = pNew;
  } else {
    pNew->pNext = pPrecedes->pNext;
    pPrecedes->pNext = pNew;
  }
  return pNew;
}