Created
September 10, 2018 15:00
-
-
Save b-coimbra/0b3b2be02acfa0a5539c602d573939ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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_t { | |
int data; | |
struct node_t *next; | |
} Node; | |
Node *create(int data, Node *node) | |
{ | |
Node *new = (Node*) malloc(sizeof(Node)); | |
if (new == NULL) | |
exit(0); | |
new->data = data; | |
new->next = node; | |
return new; | |
} | |
Node *append(int data, Node *node) | |
{ | |
if (node == NULL) | |
return NULL; | |
Node *tail = node; | |
while (tail->next != NULL) | |
tail = tail->next; | |
Node *new = create(data, NULL); | |
tail->next = new; | |
return node; | |
} | |
void list(Node *node) | |
{ | |
for (Node *i = node; i; i = i->next) | |
printf("%d\n", i->data); | |
} | |
int main() | |
{ | |
Node *head = NULL; | |
head = create(1, head); | |
head = append(5, head); | |
head = append(6, head); | |
list(head); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment