Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "stdlib.h"
- typedef struct struktura
- {
- int klucz;
- double liczba_zmiennoprzecinkowa;
- char znak;
- struct struktura *poprzedni;
- struct struktura *nastepny;
- }Struktura;
- void dodaj_na_koniec(Struktura *proba, int klucz)
- {
- Struktura *tymczasowa = proba;
- Struktura *nowa_struktura = (Struktura*)malloc(sizeof(Struktura));
- nowa_struktura->klucz = klucz;
- printf("Podaj mi liczbe: ");
- scanf("%lf", &nowa_struktura->liczba_zmiennoprzecinkowa);
- //nowa_struktura->liczba_zmiennoprzecinkowa = 4.44;
- nowa_struktura->znak = 'T';
- if (tymczasowa == NULL)
- {
- tymczasowa = nowa_struktura;
- tymczasowa->poprzedni = tymczasowa;
- tymczasowa->nastepny = tymczasowa;
- }
- else
- {
- while (tymczasowa->nastepny != NULL)
- {
- tymczasowa = tymczasowa->nastepny;
- }
- nowa_struktura->poprzedni = tymczasowa;
- nowa_struktura->nastepny = tymczasowa;
- tymczasowa->nastepny = nowa_struktura;
- }
- proba = tymczasowa;
- }
- void wyswietl(Struktura *proba, int klucz)
- {
- printf("Klucz: %d Liczba: %lf Znak: %c\n", proba->klucz, proba->liczba_zmiennoprzecinkowa, proba->znak);
- }
- int main()
- {
- int klucz = 0;
- Struktura *start = NULL;
- dodaj_na_koniec(start, klucz);
- klucz++;
- dodaj_na_koniec(start, klucz);
- klucz++;
- dodaj_na_koniec(start, klucz);
- klucz++;
- wyswietl(start, 0);
- wyswietl(start, 1);
- wyswietl(start, 2);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment