Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "bintree.h"
  3. #include "stacka.h"
  4.  
  5. static int *value;
  6. static int *left;
  7. static int *middle;
  8. static int *right;
  9.  
  10. void SetBT(int* V,int* L,int* R){
  11. value=V;
  12. left=L;
  13. right=R;
  14. }
  15.  
  16. void SetTT(int* V,int* L,int *M,int* R){
  17. //printf(" SetTT - DOPLNIT");
  18. value=V;
  19. left=L;
  20. middle=M;
  21. right=R;
  22.  
  23. }
  24.  
  25. void inorder(int root){
  26. if(left[root]!=0)inorder(left[root]);
  27. printf("%d ",value[root]);
  28. if(right[root]!=0)inorder(right[root]);
  29. }
  30.  
  31. void preorder(int root){
  32. printf("%d ",value[root]);
  33. if(left[root]!=0)preorder(left[root]);
  34. if(right[root]!=0)preorder(right[root]);
  35. }
  36.  
  37. void postorder(int root){
  38. if(left[root]!=0)postorder(left[root]);
  39. if(right[root]!=0)postorder(right[root]);
  40. printf("%d ",value[root]);
  41. }
  42.  
  43. void levelorder(int root){
  44. printf("DOPLNIT");
  45. }
  46.  
  47. void inorderNR(int v){
  48. Stack S;
  49. S = CreateStack( 12 );
  50. LT: while(left[v]!=0){
  51. Push(v,S);
  52. v=left[v];
  53. }
  54. NODE:printf("%d ",value[v]);
  55. if(right[v]!=0){
  56. v=right[v];
  57. goto LT;
  58. }
  59. if(!IsEmpty(S)){
  60. v=Top(S);
  61. Pop(S);
  62. goto NODE;
  63. }
  64. DisposeStack( S );
  65. }
  66.  
  67. void preorderNR(int v){
  68. //printf("DOPLNIT");
  69. Stack S;
  70. S = CreateStack( 12 );
  71.  
  72. }
  73.  
  74. void preorderTT(int root){
  75. //printf("DOPLNIT");
  76. printf("%d ",value[root]);
  77. if(left[root]!=0)preorderTT(left[root]);
  78. if(middle[root]!=0)preorderTT(middle[root]);
  79. if(right[root]!=0)preorderTT(right[root]);
  80.  
  81. }
  82.  
  83. void postorderTT(int root){
  84. //printf("DOPLNIT");
  85. if(left[root]!=0)postorderTT(left[root]);
  86. if(middle[root]!=0)postorderTT(middle[root]);
  87. if(right[root]!=0)postorderTT(right[root]);
  88. printf("%d ",value[root]);
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement