Skip to content

Instantly share code, notes, and snippets.

@cesarvargas00
Last active December 22, 2015 18:49
Show Gist options
  • Select an option

  • Save cesarvargas00/6515148 to your computer and use it in GitHub Desktop.

Select an option

Save cesarvargas00/6515148 to your computer and use it in GitHub Desktop.
Linked list without head.
#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