Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct list {
- struct list * next;
- int iZahl;
- };
- void Ausgabe(struct list* punkt)
- {
- int i;
- if (punkt)
- {
- for (i = 1; punkt; i++, punkt = punkt->next)
- printf("%d. Eintrag: %d \n", i, punkt->iZahl);
- }
- else
- printf("Liste leer /n");
- }
- struct list * Einfuegen(struct list* punkt, int zahl)
- {
- struct list * tmp;
- if (punkt == NULL)
- {
- tmp = (struct list*)malloc(sizeof(struct list));
- tmp->next = NULL;
- tmp->iZahl = zahl;
- return tmp;
- }
- else if (punkt->next == NULL)
- {
- punkt->next = (struct list*)malloc(sizeof(struct list));
- punkt->next->next = NULL;
- punkt->next->iZahl = zahl;
- return punkt;
- }
- else
- {
- Einfuegen(punkt->next, zahl);
- return punkt;
- }
- }
- void main()
- {
- struct list *liste;
- char iEingabe;
- int iZahl;
- liste= NULL;
- for (;;)
- {
- printf("Zahl einfuegen = e\nListe ausgeben = a\nListe loeschen = l\nBeenden = x\nEingabe: ");
- scanf("%c", &iEingabe);
- getchar();
- if (iEingabe == 'x')
- {
- break;
- }
- switch (iEingabe)
- {
- case 'e':
- printf("Welche Zahl soll eingefuegt werden: ");
- scanf("%d", &iZahl);
- getchar();
- liste = Einfuegen(liste, iZahl);
- break;
- case 'a':
- Ausgabe(liste);
- break;
- /* case 'l':
- DelList(liste);
- break;
- */ default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement