Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <conio.h>
- #include <malloc.h>
- struct Lista
- {
- Lista *next;
- float data;
- };
- Lista *Dodaj(Lista *L, const float wartosc)
- {
- if (L == NULL)
- {
- L = (Lista*)malloc(sizeof(Lista));
- L->data = wartosc;
- L->next = 0;
- }
- else
- {
- Lista *nl = (Lista*)malloc(sizeof(Lista));
- nl->data = wartosc;
- nl->next = 0;
- while (L->next != 0)
- L = L->next;
- L->next = nl;
- return nl;
- }
- return L;
- }
- int LicznikEl(Lista *L)
- {
- int licznik = 1;
- while (L->next != 0)
- {
- licznik++;
- L = L->next;
- }
- return licznik;
- }
- Lista *Nastepny(Lista *L)
- {
- return L->next;
- }
- float Odczytaj(Lista *L)
- {
- return L->data;
- }
- void ZwolnijListe(Lista *L)
- {
- if (L != NULL)
- {
- while (L->next != 0)
- {
- Lista *dL = L;
- L = L->next;
- free(dL);
- }
- free(L);
- }
- }
- int main()
- {
- printf("Lista:\n");
- Lista *X, *L = Dodaj(0, 11.0f);
- Dodaj(L, 22.0f);
- Dodaj(L, 33.0f);
- Dodaj(L, 44.0f);
- printf("Powinno byc 4, jest %d elementow listy.\n", LicznikEl(L));
- for (X = L; X != 0; X = Nastepny(X))
- printf("%.2f\n", Odczytaj(X));
- printf(".....................\n");
- Dodaj(L, 100.0f);
- printf("Jest %d elementow listy.\n", LicznikEl(L));
- for (X = L; X != 0; X = Nastepny(X))
- printf("%.2f\n", Odczytaj(X));
- ZwolnijListe(L);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment