Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Polinom Polinom :: operator+(const Polinom &A) const {
- /// Supraincarcarea operatorului de adunare - Adunarea dintre doua polinoame.
- // Daca unul dintre polinoame este nul, il returnez pe celalalt.
- if (Max == NULL) return A;
- Polinom Result;
- if (A.Max == NULL) {
- Result.Max = Result.Min = NULL;
- return Result;
- }
- Nod *P = Min, *Q = A.Min, *R;
- bool OK = true;
- while (Q != NULL || P != NULL) {
- Result.Max = new Nod;
- if (OK == true) {
- R = Result.Min = Result.Max;
- OK = false;
- }
- if (P == NULL || Q->Grad < P->Grad) {
- Result.Max->Info = Q->Info;
- Result.Max->Grad = Q->Grad;
- Q = Q->Prev;
- }
- else if (Q == NULL || Q->Grad > P->Grad) {
- Result.Max->Info = P->Info;
- Result.Max->Grad = P->Grad;
- P = P->Prev;
- }
- else {
- Result.Max->Grad = P->Grad;
- Result.Max->Info = P->Info + Q->Info;
- P = P->Prev;
- Q = Q->Prev;
- }
- if (OK == false) {
- R->Prev = Result.Max;
- Result.Max->Next = R;
- R = R->Prev;
- }
- Result.Max = Result.Max->Prev;
- }
- Result.Max = R;
- R->Prev = NULL;
- //std::cout << 1;
- return Result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement