fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct node {
  4. int val;
  5. struct node *next;
  6. };
  7. typedef struct node NODE;
  8.  
  9.  
  10. int main() {
  11. int arr1[] = {12, 43, 56, 34, 98};
  12. int arr2[] = {85, 97, 100};
  13. int size1 = sizeof(arr1) / sizeof(arr1[0]);
  14. int size2 = sizeof(arr2) / sizeof(arr2[0]);
  15.  
  16. NODE* current,*previous,*head;
  17.  
  18. for (int i = 0;i < size1;i++){
  19. current = (NODE*)malloc(sizeof(NODE));
  20. current->val = arr1[i];
  21. if (i != 0){
  22. previous->next = current;
  23. }
  24. else{
  25. head = current;
  26. }
  27. current->next = NULL;
  28. previous = current;
  29. }
  30. while(head != NULL){
  31. printf("%d ",head->val);
  32. head = head->next;
  33. }
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
12 43 56 34 98