fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct node{
  4.  
  5. int data;
  6. struct node * next;
  7.  
  8. }node;
  9.  
  10. int main(void) {
  11.  
  12. int a[3] = {3,4,2};
  13. int b[3] = {4,6,5};
  14. int i = sizeof(a)-1;
  15. int j = sizeof(b)-1;
  16. int k;
  17.  
  18. node * head_1 = malloc(sizeof(node));
  19. //node * head_2 = malloc(sizeof(node));
  20.  
  21. node * current_1;
  22. //node * current_2;
  23.  
  24. node * new_1;
  25. //node * new_2;
  26.  
  27. head_1->data = a[i];
  28. //head_2->data = b[j];
  29.  
  30. head_1->next = NULL;
  31. //head_2->next = NULL;
  32. current_1 = head_1;
  33. //current_2 = head_2;
  34.  
  35. for(k=i-1;k>=0;k--){
  36.  
  37. node * new_1 = malloc(sizeof(node));
  38. // node * new_2 = malloc(sizeof(node));
  39.  
  40. new_1->data = a[k];
  41. new_1->next=NULL;
  42. current_1->next = new_1;
  43.  
  44. // new_2->data = b[k];
  45. // current_2->next = new_2;
  46.  
  47. current_1 = current_1->next;
  48. // current_2 = current_2->next;
  49.  
  50.  
  51. }
  52.  
  53. node * temp_1;
  54. //node * temp_2;
  55.  
  56. temp_1 = head_1;
  57. while(temp_1!=NULL){
  58.  
  59. printf("%d->",temp_1->data);
  60. temp_1 = temp_1->next;
  61. }
  62.  
  63. printf("\n");
  64. //temp_2 = head_2;
  65. //while(temp_2!=NULL){
  66.  
  67. // printf("%d->",temp_2->data);
  68. // temp_2 = temp_2->next;
  69. //}
  70.  
  71. return 0;
  72. }
  73.  
Success #stdin #stdout 0s 5660KB
stdin
11
stdout
-949988064->22087->-1037684384->22087->-1037684144->0->0->-1850394835->-1657230336->2->4->3->