Results 1 to 2 of 2

Thread: C++

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Dec:2013
    Location: Ruse
    Posts: 3

    C++

    !
    :
    . /, :
    - ;
    - ;
    - ;
    - ;

    :
    Code:
    #include <iostream.h>
    
     
    struct Bukvi
    {
    	
    	char K;
    	Bukvi *L, *R; 
    };
    
    typedef Bukvi* Point;
    Point root1,root2;
    
    
    
    void Add_A_tree(char x, Point &p)
    {	
        if (p==NULL)
    	{
    		p=new Bukvi;
    		p->K=x;
    		p->L=p->R=NULL;
    	}
            else if (x<p->K)
    			Add_A_tree(x, p->L);
    	        else if (x>p->K)
    			    Add_A_tree(x, p->R);
       			     else cout<<"Ima takyv element!";
    }
    
    
    
    void Add_B_tree(char x, Point &p)
    {	
        if (p==NULL)
    	{
    		p=new Bukvi;
    		p->K=x;
    		p->L=p->R=NULL;
    	}
            else if (x<p->K)
    			Add_A_tree(x, p->L);
    	        else if (x>p->K)
    			    Add_A_tree(x, p->R);
       			     else cout<<"Ima takyv element!";
    }
    
    
    
    void print(Point p)
    {
        if (p) 
    	{
            print(p->L);
            cout<<p->K;
            print(p->R);
    	}
    }
    
    
    
    Point  search_A_tree (int x, Point p)
    {
    while ((p)&&(x!=p->K))	
     {
     if (x<p->K) p=p->L;	
    else p=p->R;	
     }
    return p;
    }
    
    
    
    void merge(
    
    
    
    void main()
    {
    	char b,Ch;
    
        root1=NULL;
    	root2=NULL;
    
        cout<<"koren = ";
        cin>>b;
    	while(b!='0')
    	{
    		Add_A_tree(b, root1);
    		cout<<"Simvol: ";
    		cin>> b;
    	}
    	cout<<"Da printiram li dyrvoto (Y/N)?: ";
        cin >> Ch;
    	if(Ch=='Y' || Ch=='y'){
        print(root1);
    	cout<<"\n";
    	}
    	
    
    	cout<<"koren = ";
        cin>>b;
    	while(b!='0')
    	{
    		Add_B_tree(b, root2);
    		cout<<"Simvol: ";
    		cin>> b;
    	}
        cout<<"Da printiram li dyrvoto (Y/N)?: ";
        cin >> Ch;
    	if(Ch=='Y' || Ch=='y'){
        print(root2);
    	cout<<"\n";
    
    
    
    	}
    }
    ( )?

  2. #2
    Registered User hateras's Avatar
    Join Date: Jan:2011
    Location: Kronos III
    Posts: 1,028
    ? , /merge/ - A Merge, B ...
    , , Add_A_tree Add_B_tree , , / Merge /?
    ----
    : " ?" - smelkomar, .
    : , .
    ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |