fork(4) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node {
  5. int data;
  6. struct node *next;
  7. } node;
  8.  
  9. node *newNode(int data) {
  10. node *new_node = (node *) malloc(sizeof(node));
  11. new_node->data = data;
  12.  
  13. new_node->next = NULL;;
  14. return new_node;
  15. }
  16.  
  17. node *insert_node(node *root, int data) {
  18. if (root == NULL)
  19. return newNode(data);
  20. else {
  21. node *cur;
  22.  
  23. cur = insert_node(root->next, data);
  24. root->next = cur;
  25.  
  26. }
  27. return root;
  28. }
  29.  
  30. void print(node *np) {
  31. if (np) {
  32. printf("(%d)", np->data);
  33. print(np->next);
  34. }
  35. }
  36.  
  37. int main() {
  38. int T = 100;
  39. node *root = NULL;
  40. while (T-- > 0) {
  41. int r = rand() % 200;
  42. root = insert_node(root, r);
  43. }
  44. print(root);
  45. printf("\n");
  46. return 0;
  47. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
(183)(86)(177)(115)(193)(135)(186)(92)(49)(21)(162)(27)(90)(59)(163)(126)(140)(26)(172)(136)(11)(168)(167)(29)(182)(130)(62)(123)(67)(135)(129)(2)(22)(58)(69)(167)(193)(56)(11)(42)(29)(173)(21)(119)(184)(137)(198)(124)(115)(170)(13)(126)(91)(180)(156)(73)(62)(170)(196)(81)(105)(125)(84)(127)(136)(105)(46)(129)(113)(57)(124)(95)(182)(145)(14)(167)(34)(164)(43)(150)(87)(8)(76)(178)(188)(184)(3)(51)(154)(199)(132)(60)(76)(168)(139)(12)(26)(186)(94)(139)