Advertisement
Guest User

online2

a guest
Jan 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct IntNode
  5. {
  6. struct IntNode *next;
  7. int data;
  8. } IntNode;
  9. IntNode *head;
  10.  
  11.  
  12. IntNode * insertLast(IntNode*head, int c)
  13. {
  14. IntNode *tmp, *cursor;
  15. if (head==NULL)
  16. {
  17. tmp= malloc(sizeof(IntNode));
  18. tmp->data = c;
  19. tmp->next = head;
  20. return tmp;
  21. }
  22. else
  23. {
  24. cursor=head;
  25. while (cursor->next != NULL)
  26. {
  27. cursor =cursor->next;
  28. }
  29. tmp= malloc(sizeof(IntNode));
  30. tmp->data = c;
  31. tmp->next = NULL;
  32. cursor->next=tmp;
  33. return head;
  34. }
  35. }
  36.  
  37. void printList(IntNode *head)
  38. {
  39. IntNode *zeiger;
  40. zeiger=head;
  41. printf("Beginn der Liste ( ");
  42. while (zeiger =!NULL)
  43. {
  44. printf("%d", zeiger-> data);
  45. printf(" ");
  46. zeiger=zeiger->next;
  47. }
  48. printf(")"); // Ende der Liste
  49. }
  50.  
  51.  
  52. int main()
  53. {
  54. IntNode *head=NULL;
  55. IntNode *L1;
  56. L1= insertLast(L1,3);
  57. printList(L1);
  58.  
  59.  
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement