fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Node {
  5. int data;
  6. struct Node *next;
  7. };
  8.  
  9. typedef struct Node *No;
  10. typedef struct Node Elem;
  11.  
  12. void push1(struct Node** headRef, int data) {
  13. struct Node* newNode = malloc(sizeof(struct Node));
  14. newNode->data = data;
  15. newNode->next = *headRef;
  16. *headRef = newNode;
  17. }
  18.  
  19. No *push2(No *li, int data) {
  20. Elem *no = malloc(sizeof(Elem));
  21. no->data = data;
  22. no->next = (*li);
  23. *li = no;
  24. return li;
  25. }
  26.  
  27. int main() {
  28. int arr[] = {1, 2, 3};
  29. int i = 0;
  30. struct Node *head = NULL;
  31. push1(&head, arr[i]);
  32. printf("%d", head->data);
  33. No *li = malloc(sizeof(No));
  34. No *result = push2(li, arr[i]);
  35. printf("%d", (*li)->data);
  36. printf("%d", (*result)->data);
  37. }
  38.  
  39. //https://pt.stackoverflow.com/q/449408/101
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
111