VEndymionV

Untitled

Oct 16th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3.  
  4. typedef struct struktura
  5. {
  6.     int klucz;
  7.     double liczba_zmiennoprzecinkowa;
  8.     char znak;
  9.     struct struktura *poprzedni;
  10.     struct struktura *nastepny;
  11. }Struktura;
  12.  
  13. void dodaj_na_koniec(Struktura *proba, int klucz)
  14. {
  15.     Struktura *tymczasowa = proba;
  16.     Struktura *nowa_struktura = (Struktura*)malloc(sizeof(Struktura));
  17.     nowa_struktura->klucz = klucz;
  18.     printf("Podaj mi liczbe: ");
  19.     scanf("%lf", &nowa_struktura->liczba_zmiennoprzecinkowa);
  20.     //nowa_struktura->liczba_zmiennoprzecinkowa = 4.44;
  21.     nowa_struktura->znak = 'T';
  22.     if (tymczasowa == NULL)
  23.     {
  24.         tymczasowa = nowa_struktura;
  25.         tymczasowa->poprzedni = tymczasowa;
  26.         tymczasowa->nastepny = tymczasowa;
  27.     }
  28.     else
  29.     {
  30.         while (tymczasowa->nastepny != NULL)
  31.         {
  32.             tymczasowa = tymczasowa->nastepny;
  33.         }
  34.         nowa_struktura->poprzedni = tymczasowa;
  35.         nowa_struktura->nastepny = tymczasowa;
  36.         tymczasowa->nastepny = nowa_struktura;
  37.        
  38.     }
  39.     proba = tymczasowa;
  40. }
  41.  
  42. void wyswietl(Struktura *proba, int klucz)
  43. {
  44.     printf("Klucz: %d  Liczba: %lf  Znak: %c\n", proba->klucz, proba->liczba_zmiennoprzecinkowa, proba->znak);
  45. }
  46.  
  47. int main()
  48. {
  49.     int klucz = 0;
  50.     Struktura *start = NULL;
  51.     dodaj_na_koniec(start, klucz);
  52.     klucz++;
  53.     dodaj_na_koniec(start, klucz);
  54.     klucz++;
  55.     dodaj_na_koniec(start, klucz);
  56.     klucz++;
  57.     wyswietl(start, 0);
  58.     wyswietl(start, 1);
  59.     wyswietl(start, 2);
  60.     system("pause");
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment