#include<iostream> using namespace std; typedef struct node { int data; node *left; node *right; }; typedef struct node *BTREE; BTREE ekle(BTREE root,int veri) { if(root==NULL) { root=new node(); root->data=veri; root->left=NULL; root->right=NULL; } else { if(veri<root->data) root->left=ekle(root->left,veri); else root->right=ekle(root->right,veri); } return root; } void inorder(BTREE root)//left,root,right; { if(root!=NULL) { inorder(root->left); cout<<root->data<<endl; inorder(root->right); } } void preorder(BTREE root)//root,left,right; { if(root!=NULL) { cout<<root->data<<endl; preorder(root->left); preorder(root->right); } } void postorder(BTREE root)//left,right,root; { if(root!=NULL) { postorder(root->left); postorder(root->right); cout<<root->data<<endl; } } int esayisi(BTREE root) { if(root==NULL) return 0; else { return esayisi(root->left)+esayisi(root->right)+1; } } main() { BTREE root=NULL; root=ekle(root,30); ekle(root,20); ekle(root,40); ekle(root,19); ekle(root,45); ekle(root,39); inorder(root); //postorder(root); cout<<"elemansayisi:"<<esayisi(root); }
sonraki
« Prev Post
« Prev Post
Önceki
Next Post »
Next Post »
Kaydol:
Kayıt Yorumları (Atom)
Show Conversion Code Hide Conversion Code Show Emoticon Hide Emoticon