Last active
December 22, 2015 18:49
-
-
Save cesarvargas00/6515148 to your computer and use it in GitHub Desktop.
Linked list without head.
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> | |
| struct cel | |
| { | |
| int value; | |
| struct cel *next; | |
| }; | |
| typedef struct cel cell; | |
| void add(cell **list, int valor); | |
| void print(cell *list); | |
| int main(int argc, char const *argv[]) | |
| { | |
| cell *list; | |
| add(&list, 3); | |
| add(&list, 4); | |
| add(&list, 5); | |
| add(&list, 6); | |
| print(list); | |
| return 0; | |
| } | |
| void add(cell **list, int valor){ | |
| cell *new; | |
| new = malloc(sizeof(cell)); | |
| (*new).value = valor; | |
| (*new).next = NULL; | |
| if (*list==NULL) | |
| { | |
| *list = new; | |
| }else{ | |
| (*new).next = (**list).next; | |
| (**list).next = new; | |
| } | |
| } | |
| void print(cell *list){ | |
| cell *ptr = list; | |
| while(ptr!=NULL){ | |
| printf("%d\n", (*ptr).value); | |
| ptr = (*ptr).next; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment