Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // arbore binar_dinamic.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #pragma warning(disable:4996)
- using namespace std;
- struct nod {
- int info;
- nod* stg;
- nod* dr;
- };
- void creare(nod* n);
- void creare_stg(nod *tata) {
- int info;
- cout << "Introdu fiul stang al lui " << tata->info<<" "; cin >> info;
- if (info) {
- nod* n = new nod;
- n->info = info;
- tata->stg = n;
- tata = n;
- creare(n);
- }
- else
- tata->stg = NULL;
- }
- void creare_dr(nod* tata) {
- int info;
- cout << "Introdu fiul drept al lui " << tata->info<<" "; cin >> info;
- if (info) {
- nod* n = new nod;
- n->info = info;
- tata->dr = n;
- tata = n;
- creare(n);
- }
- else
- tata->dr = NULL;
- }
- void creare(nod*n) {
- creare_stg(n);
- creare_dr(n);
- }
- void srd(nod* n){
- if (n){
- srd(n->stg);
- cout << n->info << " ";
- srd(n->dr);
- }
- }
- void rsd(nod* n) {
- if (n) {
- cout << n->info << " ";
- rsd(n->stg);
- rsd(n->dr);
- }
- }
- void sdr(nod* n) {
- if (n) {
- sdr(n->stg);
- sdr(n->dr);
- cout << n->info << " ";
- }
- }
- int main()
- {
- nod* radacina = new nod;
- cout << "Introduceti radacina:"; cin >> radacina->info;
- creare(radacina);
- cout << "SRD: "; srd(radacina);
- cout << endl;
- cout << "RSD: "; rsd(radacina);
- cout << endl;
- cout << "SDR: "; sdr(radacina);
- return 0;
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement