Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <iostream>
  5.  
  6. struct Node
  7. {
  8. int data;
  9. Node *kiri;
  10. Node *kanan;
  11.  
  12. };
  13.  
  14. void tambah(Node **root, int databaru)
  15. {
  16. if ((*root) == NULL)
  17. {
  18. Node *baru;
  19.  
  20. baru = new Node;
  21. baru -> data=databaru;
  22. baru->kiri=NULL;
  23. baru->kanan=NULL;
  24. (*root)=baru;
  25. (*root)->kiri=NULL;
  26. (*root)->kanan+NULL;
  27. printf("data bertambah!");
  28. }
  29.  
  30. else if (databaru<(*root)->data)
  31. tambah(&(*root)->kiri,databaru );
  32.  
  33. else if (databaru<(*root)->data)
  34. tambah(&(*root)->kanan,databaru );
  35.  
  36. else if (databaru<(*root)->data)
  37. printf("Data Sdah ada");
  38. }
  39.  
  40.  
  41. void preOrder (Node *root)
  42. {
  43. if(root!=NULL)
  44. {
  45. printf("&d", root->data);
  46. preOrder(root->kiri);
  47. preOrder(root->kanan);
  48.  
  49. }
  50. }
  51.  
  52.  
  53.  
  54. void inOrder (Node *root)
  55. {
  56. if(root!=NULL)
  57. {
  58. inOrder(root->kiri);
  59. printf("&d", root->data);
  60. inOrder(root->kanan);
  61.  
  62. }
  63. }
  64.  
  65.  
  66. void postOrder (Node *root)
  67. {
  68. if(root!=NULL)
  69. {
  70. postOrder(root->kiri);
  71. postOrder(root->kanan);
  72. printf("&d", root->data);
  73.  
  74. }
  75. }
  76.  
  77. int main()
  78. {
  79. int pil,data;
  80. Node *pohon;
  81. pohon = NULL;
  82. do
  83. {
  84. system("cls");
  85. printf("\t#PROGRAM Tree#");
  86. printf("1.tambah\n");
  87. printf("2.lihat pre\n");
  88. printf("3.lihat in\n");
  89. printf("4.lihat post-order\n");
  90. printf("5.exit\n");
  91. printf("Pilihan :");
  92. scanf("&d",&pil);
  93. switch(pil)
  94. {
  95. case 1:
  96. }
  97.  
  98.  
  99.  
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement