Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- struct item {
- char info;
- item *L, *R;
- };
- typedef item* point;
- point Root;
- void Create_B_Tree(point &P) {
- char x;
- cin>>x;
- if (x!='0') {
- P=new item; P->info=x; P->L=P->R=NULL;
- cout<<"ляв наследник на "<<P->info<< "= ";
- Create_B_Tree(P->L);
- cout<<"десен наследник на "<<P->info<< "= ";
- Create_B_Tree(P->R);
- }
- }
- void Print1(point P) {
- if (P) {
- cout << P->info;
- Print1(P->L);
- Print1(P->R);
- }
- }
- void Print2(point P) {
- if (P) {
- cout << P->info;
- Print2(P->L);
- Print2(P->R);
- }
- }
- void Print3(point P) {
- if (P) {
- cout << P->info;
- Print3(P->L);
- Print3(P->R);
- }
- }
- /*
- void CountP(point P, int &C){
- if (P) {
- C++;
- CountP (P->L, C);
- CountP (P->R, C);
- }
- }
- */
- /*int CountP(point P){
- if (P) return 1 + CountP(P->L) + CountP(P->R);
- else return 0;
- }
- */
- int CountOP(point P){
- if (P) {
- if (P->info == '+' || P->info == '-' || P->info == '*' || P->info == '/') {
- return 1 + CountOP(P->L) + CountOP(P->R);
- } else {
- return CountOP(P->L) + CountOP(P->R);
- }
- } else {
- return 0;
- }
- }
- int CountL(point P){
- if (P) {
- if (CountL(P->L) != 0 || CountL(P->R) != 0) {
- return CountL(P->L) + CountL(P->R);
- } else {
- return 1;
- }
- } else {
- return 0;
- }
- }
- int CountD(point P){
- if (P) {
- if (CountD(P->L) > CountD(P->R)) {
- return 1 + CountD(P->L);
- } else {
- return 1 + CountD(P->R);
- }
- } else {
- return 0;
- }
- }
- void main() {
- system("chcp 1251");
- Root=NULL;
- cout<<"корен = ";
- Create_B_Tree(Root);
- //Print1(Root);
- //Print2(Root);
- //Print3(Root);
- //int Lenght=0;
- //CountP(Root, Lenght); cout<< Lenght;
- //cout << CountP(Root);
- //cout << CountOP(Root);
- cout << CountL(Root);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement