Created
July 23, 2016 13:08
-
-
Save wohhie/5bbd64d0772821c6da97c3f86e54d784 to your computer and use it in GitHub Desktop.
//LinkedList Insert & display
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
| //LinkedList code | |
| //insert and display list | |
| #include <stdio.h> | |
| #include <cstdlib> | |
| struct Node { | |
| int val; | |
| struct Node *next; | |
| }; | |
| typedef struct Node item; | |
| int main() { | |
| item *curr, *head; | |
| int i; | |
| head = NULL; | |
| for (i = 1; i < 10; i++) { | |
| curr = (item *)malloc(sizeof(item)); | |
| curr->val = i; | |
| curr->next = head; | |
| head = curr; | |
| } | |
| curr = head; | |
| printf("\n"); | |
| while (curr) { | |
| printf("%d->", curr->val); | |
| curr = curr->next; | |
| } | |
| printf("NULL"); | |
| printf("\n"); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment