Facebook
From Little Gorilla, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 225
  1. #include <stdlib.h>
  2.  
  3. typedef struct{int d;
  4. struct tElement *lewe, *prawe;
  5. }tElement;
  6.  
  7. typedef tElement *tWsk;
  8.  
  9. tWsk K;
  10. int n;
  11.  
  12. void wstaw(tWsk *K, int element)
  13. {
  14.     if((*K)==NULL)
  15.     {
  16.         (*K)=(tElement*)malloc(sizeof(tElement));
  17.         (*K)->d=element;
  18.         (*K)->lewe=NULL;
  19.         (*K)->prawe=NULL;
  20.     }
  21.     else if(element<(*K)->d) wstaw(&(*K)->lewe, element);
  22.     else wstaw(&(*K)->prawe, element);
  23. }
  24.  
  25. void drukuj(tWsk K, int wciecie)
  26. {
  27.     int i;
  28.     if(K!=NULL)
  29.     {
  30.         drukuj(K->prawe, wciecie+1);
  31.         for(i=1; i<=wciecie; i++)
  32.         {
  33.             printf(" ");
  34.             printf("%2d\n", K->d);
  35.             drukuj(K->lewe, wciecie+1);
  36.         }
  37.     }
  38. }
  39.  
  40. void main()
  41. {
  42.     int i, liczba;
  43.     K=NULL;
  44.     printf("Ile bedzie liczb?: ");
  45.     scanf("%d", &n);
  46.     for(i=1; i<=n; i++)
  47.     {
  48.         printf("%d element: ", i); scanf("%d", &liczba);
  49.         wstaw(&K, liczba);
  50.     }
  51.     printf("\n\n");
  52.     drukuj(K,0);
  53. }
  54.