fork(4) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. struct drzewo
  7. {
  8. int liczba;
  9. drzewo *lewy,*prawy;
  10. drzewo(int liczba):liczba(liczba),lewy(0),prawy(0) {}
  11. };
  12.  
  13. int main()
  14. {
  15. drzewo *korzen=0,**iter=&korzen;
  16. int value=0,ch;
  17. bool ujemna=false;
  18. while((ch=getchar())!=EOF)
  19. {
  20. if(ch=='-') ujemna=true;
  21. else if(ch == 'L') iter = &((*iter)->lewy);
  22. else if(ch == 'R') iter = &((*iter)->prawy);
  23. else if(isdigit(ch)) value=value*10+ch-'0';
  24. else if(ch=='\n')
  25. {
  26. *iter=new drzewo(ujemna?-value:value);
  27. ujemna=value=0;
  28. iter=&korzen;
  29. }
  30. }
  31. cout << "Lewy Lewy wynosi "<< korzen->lewy->lewy->liczba << endl;
  32. cout << "Lewy wynosi "<< korzen->lewy->liczba << endl;
  33. cout << "Lewy Prawy wynosi "<< korzen->lewy->prawy->liczba << endl;
  34. cout << "Korzen wynosi " << korzen->liczba <<endl;
  35. cout << "Prawy Lewy wynosi "<< korzen->prawy->lewy->liczba << endl;
  36. cout << "Prawy wynosi "<< korzen->prawy->liczba << endl;
  37. cout << "Prawy Prawy wynosi "<< korzen->prawy->prawy->liczba << endl;
  38. return 0;
  39. }
  40.  
Runtime error #stdin #stdout 0s 3432KB
stdin
4
-2 L
-6 R
1 LL
3 LR
5 RL
7 RR
stdout
Lewy Lewy wynosi 1
Lewy wynosi -2
Lewy Prawy wynosi 3
Korzen wynosi 4
Prawy Lewy wynosi 5
Prawy wynosi -6