Platinum Partner

Linked Lists In C

// I coded this little piece of overkill for USACO's "Milk2" algorithm training problem. 
// I'm leaving out the actual solution to the problem, but am leaving in the basic 
// manipulations to the linked list itself.


#include 
#include 

typedef struct timeNode timeNode;
struct Node {
    int begin;  /* i.e., the data part */
    int end;
    timeNode *next;  /* ptr to the next element */
};

timeNode* addNode(timeNode *last, int begin, int end) {
    timeNode *node;
    node = (timeNode*)malloc(sizeof(timeNode));
    node->begin = begin;
    node->end = end;
    node->next = NULL;
    if (last != NULL) {
        last->next = node;
    }
    return node;
    
}

void insertNode(timeNode *before, int begin, int end) {
    timeNode *add = (timeNode*)malloc(sizeof(timeNode));
    add->begin = begin;
    add->end = end;
    add->next = before->next;
    before->next = add;
}

timeNode* insertBefore(timeNode *before, int begin, int end) {
    timeNode *add = (timeNode*)malloc(sizeof(timeNode));
    add->begin = begin;
    add->end = end;
    add->next = before; 
    return add;
}


timeNode* deleteNode(timeNode *toDelete) {
    timeNode *retval = toDelete->next;
    free(toDelete);
    return retval;
    
}

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}