/ Published in: Haskell

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.
Expand |
Embed | Plain Text
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 *node; node = (timeNode*)malloc(sizeof(timeNode)); node->begin = begin; node->end = end; node->next = 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; }
Comments
