Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct list {
  5.  
  6. struct list * next;
  7. int iZahl;
  8.  
  9. };
  10.  
  11. void Ausgabe(struct list* punkt)
  12. {
  13. int i;
  14. if (punkt)
  15. {
  16. for (i = 1; punkt; i++, punkt = punkt->next)
  17.  
  18. printf("%d. Eintrag: %d \n", i, punkt->iZahl);
  19. }
  20. else
  21. printf("Liste leer /n");
  22. }
  23.  
  24. struct list * Einfuegen(struct list* punkt, int zahl)
  25. {
  26. struct list * tmp;
  27. if (punkt == NULL)
  28. {
  29. tmp = (struct list*)malloc(sizeof(struct list));
  30. tmp->next = NULL;
  31. tmp->iZahl = zahl;
  32. return tmp;
  33. }
  34. else if (punkt->next == NULL)
  35. {
  36. punkt->next = (struct list*)malloc(sizeof(struct list));
  37. punkt->next->next = NULL;
  38. punkt->next->iZahl = zahl;
  39. return punkt;
  40. }
  41. else
  42. {
  43. Einfuegen(punkt->next, zahl);
  44. return punkt;
  45. }
  46. }
  47.  
  48. void main()
  49. {
  50. struct list *liste;
  51. char iEingabe;
  52. int iZahl;
  53.  
  54. liste= NULL;
  55. for (;;)
  56. {
  57. printf("Zahl einfuegen = e\nListe ausgeben = a\nListe loeschen = l\nBeenden = x\nEingabe: ");
  58. scanf("%c", &iEingabe);
  59. getchar();
  60. if (iEingabe == 'x')
  61. {
  62. break;
  63. }
  64. switch (iEingabe)
  65. {
  66.  
  67. case 'e':
  68. printf("Welche Zahl soll eingefuegt werden: ");
  69. scanf("%d", &iZahl);
  70. getchar();
  71. liste = Einfuegen(liste, iZahl);
  72. break;
  73. case 'a':
  74. Ausgabe(liste);
  75. break;
  76. /* case 'l':
  77. DelList(liste);
  78. break;
  79. */ default:
  80. break;
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement