Created
September 30, 2010 02:25
-
-
Save limitedmage/603920 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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct _node { | |
int value; | |
struct _node *next; | |
} node; | |
void CheckNotNull(void *pointer); | |
node *BuildOneTwoThree(); | |
void PrintList(node *head); | |
int main() { | |
node *list = BuildOneTwoThree(); | |
PrintList(list); | |
return 0; | |
} | |
node *BuildOneTwoThree() { | |
node *head; | |
head = (node *) malloc(sizeof(node)); | |
CheckNotNull(head); | |
head->value = 1; | |
head->next = (node *) malloc(sizeof(node)); | |
CheckNotNull(head->next); | |
head->next->value = 2; | |
head->next->next = (node *) malloc(sizeof(node)); | |
CheckNotNull(head->next->next); | |
head->next->next->value = 3; | |
head->next->next->next = NULL; | |
return head; | |
} | |
void PrintList(node *head) { | |
node *curr = head; | |
while (curr != NULL) { | |
printf("%d ", curr->value); | |
curr = curr->next; | |
} | |
printf("\n"); | |
} | |
void CheckNotNull(void *pointer) { | |
if (pointer == NULL) { | |
printf("Error: pointer is null.\n"); | |
exit(-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment