Advertisement
mauricioribeiro

Simple linked list

Aug 9th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct num{
  5.     int content;
  6.     struct num *next;
  7. };
  8. typedef struct num numbers;
  9.  
  10. void Insert(int new_content,numbers *id_num){
  11.     numbers *mold;
  12.     mold = malloc (sizeof (numbers));
  13.     mold->content = new_content;
  14.     mold->next = id_num->next;
  15.     id_num->next = mold;
  16. }
  17.  
  18. void PrintContent(numbers *id_num){
  19.     if(id_num!=NULL){
  20.         printf("%d\n",id_num->content);
  21.         PrintContent(id_num->next);
  22.     }
  23. }
  24.  
  25. int main(){
  26.     numbers head;
  27.     numbers *list_numbers;
  28.  
  29.     list_numbers = &head;
  30.     head.next = NULL;
  31.  
  32.     Insert(10,list_numbers);
  33.     Insert(5,list_numbers);
  34.     Insert(3,list_numbers);
  35.     Insert(8,list_numbers);
  36.     Insert(1,list_numbers);
  37.     PrintContent(list_numbers->next);
  38.  
  39.     system("pause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement