fork download
  1. #include<string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. struct node{
  6. int key;
  7. int value;
  8. struct node *next;
  9. };
  10.  
  11. struct LinkedList {
  12. struct node *head;
  13. };
  14.  
  15. void createNode(int key, int value, struct node **node) {
  16. struct node *new_node = malloc(sizeof(struct node));
  17. new_node->key = key;
  18. new_node->value = value;
  19. new_node->next = NULL;
  20. struct node **tmp = node;
  21. while(*tmp != NULL)
  22. *tmp = (*tmp)->next;
  23. *tmp = new_node;
  24.  
  25. }
  26.  
  27. void traverseNode(struct LinkedList *lList) {
  28. struct node * current = lList->head;
  29. while(current != NULL) {
  30. printf("Key: %i, Value: %i", current->key, current->value);
  31. current = current->next;
  32. }
  33. }
  34.  
  35. int main()
  36. {
  37. struct LinkedList *lList = malloc(sizeof(struct LinkedList));
  38. lList->head = NULL;
  39.  
  40. createNode(1,1,&lList->head);
  41.  
  42. traverseNode(lList);
  43. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Key: 1, Value: 1