Created
October 26, 2012 12:56
-
-
Save chrisdew/3958628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A task on a task list (and also possibly on an outstanding_task_list. | |
struct task { | |
int priority; | |
struct list_node task_list; | |
const char *task_name; | |
struct list_node outstanding_task_list; | |
}; | |
void list() { | |
printf("list\n"); | |
struct task mow_lawn = { .priority=23, .task_name="mow lawn"}; | |
struct task water_garden = { .priority=22, .task_name="water garden"}; | |
struct task feed_dog = { .priority=21, .task_name="feed dog"}; | |
struct list_node task_list; | |
struct list_node outstanding_task_list; | |
INIT_LIST_NODE(&task_list); | |
INIT_LIST_NODE(&outstanding_task_list); | |
list_add(&(mow_lawn.task_list), &task_list); | |
list_add(&(mow_lawn.outstanding_task_list), &outstanding_task_list); | |
list_add(&(water_garden.task_list), &task_list); | |
list_add(&(water_garden.outstanding_task_list), &outstanding_task_list); | |
list_add(&(feed_dog.task_list), &task_list); | |
struct list_node *pos; | |
list_for_each(pos, &task_list) { | |
struct task *tmp = list_entry(pos, struct task, task_list); | |
printf("%i %s\n", tmp->priority, tmp->task_name); | |
} | |
list_for_each(pos, &outstanding_task_list) { | |
struct task *tmp = list_entry(pos, struct task, outstanding_task_list); | |
printf("%i %s\n", tmp->priority, tmp->task_name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment