Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct listaelem
  4. {
  5. int data;
  6. struct listaelem* next;
  7.  
  8. }listaelem;
  9.  
  10. listaelem* push_front(listaelem* head, int d)
  11. {
  12. listaelem* p = (listaelem*)malloc(sizeof(listaelem));
  13. p->data = d;
  14. p->next = head;
  15. head = p;
  16.  
  17. return head;
  18. }
  19.  
  20. int main()
  21. {
  22. listaelem* head = NULL;
  23. head = push_front(head, 2);
  24. head = push_front(head, 5);
  25.  
  26. listaelem* p = head;
  27. while (p != NULL)
  28. {
  29. printf("%d ", p->data);
  30. p = p->next;
  31. }
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement