fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef int Int;
  6. typedef struct _LinkedListInt{
  7. Int value;
  8. struct _LinkedListInt *next;
  9. } LinkedListInt;
  10.  
  11. LinkedListInt *LinkedListInt_New(const Int *value){
  12. LinkedListInt *result = calloc(0, sizeof(LinkedListInt));
  13. memcpy(&result->value, value, sizeof(Int));
  14. return result;
  15. }
  16.  
  17. void LinkedListInt_Free(LinkedListInt *list){
  18. LinkedListInt *prev;
  19. while(prev = list){
  20. list = list->next;
  21. free(prev);
  22. } free(list);
  23. }
  24.  
  25. LinkedListInt *LinkedListInt_Top(LinkedListInt *list){
  26. if(!list) return ((void *)0);
  27. while(list->next)
  28. list = list->next;
  29. return list;
  30. }
  31.  
  32. int LinkedListInt_Push(LinkedListInt *list, const Int *value){
  33. if(list == ((void *)0))
  34. return LinkedListInt_New(value);
  35. LinkedListInt *top = LinkedListInt_Top(list);
  36. top->next = LinkedListInt_New(value);
  37. return list;
  38. }
  39.  
  40. void LinkedListInt_ForEach(const LinkedListInt *list, void(*op)(const Int *)){
  41. while(list){
  42. op(&list->value);
  43. list = list->next;
  44. }
  45. }
  46.  
  47. int main(void){ return 0;/* identical */ }
Success #stdin #stdout 0s 2048KB
stdin
Standard input is empty
stdout
Standard output is empty