Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class TreeNode{
  2. public:
  3. char data;
  4. TreeNode* Left, Right;
  5. int count;
  6. TreeNode(){
  7. Left=Right=NULL;
  8. }
  9. }
  10. void PrintcountChar(TreeNode* &root){ //gia su duyet NLR, duyet sao tuy ong.
  11. if(root==NULL) return;
  12. cout<<"count:"<<root->data<<" :"<<root->count;
  13. PrintcountChar(root->Left);
  14. PrintcountChar(root->Right);
  15. }
  16. void AddTreeNode(TreeNode* &root, char data){
  17. if(root==NULL){
  18. root=new TreeNode; root->data=data;
  19. root->count=1;
  20. return;
  21. }
  22. else if(data==root->data){
  23. root->count+=1;
  24. return;
  25. }
  26. else if(data > root->data) AddTreeNode(root->Right, data);
  27. else if(data < root->data) AddTreeNode(root->Left, data);
  28. }
  29. void main(){
  30. char* str;
  31. cout<<"input :"; cin>>str;
  32. TreeNode* root=new TreeNode;
  33. //while hay for gi do, cho no doc het tu ki tu 1 cua str
  34. AddTreeNode(root, str[i]);
  35. //duyet qua het cay, roi xuat ra so lan xuat hien cua ki tu
  36. //vd duyet LNR
  37. PrintcountChar(root);
  38. //con cau 1.b, thi ong viet ham search(TreeNode*&root, char target) search
  39. //tim dc con tro pResult roi xuat ra pResult->count
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement