NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <iostream>

using namespace std;

// ar.cpp

class nod
{
public:
char inf; // Informatia poate fi orice alta structura de
//date
int dim;
nod *tab[100]; // e indicat a se folosi containerul
//vector din biblioteca standard C++
};
nod * crearb(); // Functia pentru crearea arborelui
//citire Arbori cu radacina(3).doc, cu paranteze 4(11(5,10),7,8(2,3,1(6)),9(12))
void padinc(nod *); // Functia pentru parcurgerea in adincime
void plat(nod *); // Functia pentru parcurgerea in latime
class queue{ /* e indicat sa se foloseasca containerul
inf nr fii
4 4
11/b 2
5 0
10/a 0
7 0
8 3
2 0
3 0
1 1
6 0
9 1
12/c 0
*/
//queue din biblioteca standard C++
public:
queue(): size(0), end(0)
{
}
void pop(); // functia elimina un element din coada
void push(nod *); // aduaga un element in coada
nod * front(); // returneaza un element din coada
//fara sa-l elimine
int empty();
private:
int size, end;
nod *t[100]; // structura de date folosita pentru
// implementarea cozii poate fi o lista dinamica
};
void queue::pop()
{
if (end>0)
end--;
else
{
cerr << "queue empty" << endl;

}
}
void queue::push(nod *p)
{
for(int i=end; i>0; i--)
t[i]=t[i-1];
t[0]=p;
end++;
}
nod * queue::front()
{
if (end>0)
return t[end-1];
else
{
cerr << "queue empty" << endl;
return 0;
}
}
int queue::empty()
{
if (end == 0)
return 1;
else
return 0;
}
int main()
{
//Creez arborele
nod * root;
root = crearb();
cout << "Parcurgere in adincime:" << endl;//4,11,5,10,7,8,2,3,1,6,9,12
padinc(root);
cout << endl;
cout << "Parcurgere in latime:" << endl;//4,11,7,8,9,5,10,2,3,1,12,6
plat(root);
return 0;
}
nod * crearb()
{
char ch;
int n,i;
nod *p;
cout << "Inf="; cin >> ch;
p = new nod;
p->inf = ch;
cout << "Cati fii are?"; cin >> n;
p->dim = n;
for(i=0; i < p->dim; i++)
p->tab[i] = crearb();
return p;

}
// Parcurgerea in adincime este de fapt parcurgerea in
// preordine
//se parcurge radacina urmata de fii de la stanga la dreapta
void padinc(nod *p)
{
int i;
// if(p!=NULL) { testul este inutil
cout << p->inf;
for(i=0; i<p->dim; i++)
padinc(p->tab[i]);
// }
}

// Parcurgerea in latime utilizeaza structura de coada
// Algoritmul este nerecursiv si poate fi inteles destul de
// simplu din codul de mai jos;
void plat(nod *p)
{
queue Q; nod *t; int i;
Q.push(p);
while (!Q.empty())
{
t = Q.front();
Q.pop();
cout << t->inf;
for(i=0; i<t->dim; i++)
Q.push(t->tab[i]);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.