Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Nod {
- int numar;
- Nod* next;
- };
- bool eGol(Nod* top) {
- return top == NULL;
- }
- Nod* creeazaNod(int valoare)
- {
- Nod* nodNou = new Nod();
- nodNou -> numar = valoare;
- nodNou -> next = NULL;
- return nodNou;
- }
- void adaugaNod(Nod* &top, int valoare)
- {
- Nod* nodNou = creeazaNod(valoare);
- nodNou -> next = top;
- top = nodNou;
- }
- int varfulStivei(Nod* top)
- {
- if(eGol(top))
- return 0;
- return top -> numar;
- }
- void afiseazaStiva(Nod* top)
- {
- while(top != NULL)
- {
- cout << top -> numar << " ";
- top = top -> next;
- }
- }
- void construieste(int V[], int n)
- {
- Nod* stive[100]; int nMax = 0;
- adaugaNod(stive[0], V[0]);
- nMax += 1;
- for(int i = 1; i < n; i++)
- {
- bool plasat = false;
- for(int j = 0; j < nMax; j++)
- {
- if(V[i] < varfulStivei(stive[j]))
- {
- adaugaNod(stive[j], V[i]);
- plasat = true;
- break;
- }
- }
- if(plasat == false)
- {
- adaugaNod(stive[nMax], V[i]);
- nMax += 1;
- }
- }
- for(int i = 0; i < nMax; i++)
- {
- cout << "Stiva " << i << " : ";
- afiseazaStiva(stive[i]);
- cout << "\n";
- }
- }
- int main()
- {
- int V[10] = {3, 1, 2, 6, 5, 7, 4}, n = 7;
- construieste(V, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement