Created
June 5, 2013 22:32
-
-
Save charlierm/5717863 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> | |
struct SLNode { | |
struct SLNode *next; | |
long value; | |
}; | |
void sl_push_front(struct SLNode **list, long v){ | |
//Create new node, add the value. | |
struct SLNode* node = malloc(sizeof(struct SLNode)); | |
node->value = v; | |
node->next = *list; | |
//Change the head to be the newly created node | |
*list = node; | |
return; | |
} | |
void sl_display(struct SLNode *list){ | |
while(list){ | |
printf("%lu\n", list->value); | |
list = list->next; | |
} | |
return; | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
struct SLNode *list = NULL; | |
for (int i = 0; i < 10; ++i) | |
{ | |
sl_push_front(&list, i); | |
} | |
sl_display(list); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment