# Posted By

rtperson on 12/02/12

# Statistics

Viewed 398 times
Favorited by 0 user(s)

# Related snippets  I bit of overkill for USACO's "Milk2" algorithm training problem. This problem would be better suited to an interval tree, but here it is.

Copy this code and paste it in your HTML
`#include <stdio.h>#include <stdlib.h> 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; }` Subscribe to comments