fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node {
  5. int val;
  6. struct node *next;
  7. } Node;
  8.  
  9. Node *head = NULL;
  10.  
  11. void insHead(int x){
  12. Node *p;
  13. p = (Node *)malloc(sizeof(Node));
  14. p->next = head;
  15. p->val = x;
  16. head = p;
  17. }
  18.  
  19. void printL(){
  20. Node *p = head;
  21. while(p != NULL){
  22. printf("%d ", p->val);
  23. p = p->next;
  24. }
  25. }
  26.  
  27. int main(void){
  28. insHead(1);
  29. insHead(2);
  30. insHead(2);
  31. insHead(3);
  32. printL();
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
3 2 2 1