Created
July 25, 2017 06:14
-
-
Save kdelwat/bf50b7ac269ed0d0f182263e60169543 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 node { | |
int data; | |
struct node *next; | |
}; | |
struct node *new_node(int data, struct node *next); | |
void print_list(struct node *head); | |
int main(void) { | |
struct node *head = new_node(4, NULL); | |
head = new_node(3, head); | |
head = new_node(2, head); | |
head = new_node(1, head); | |
print_list(head); | |
} | |
struct node *new_node(int data, struct node *next) { | |
struct node *new = malloc(sizeof (struct node)); | |
new->data = data; | |
new->next = next; | |
return new; | |
} | |
void print_list(struct node *head) { | |
printf("Your list: "); | |
while(head != NULL) { | |
printf("%d ", head->data); | |
head = head->next; | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment