multiply two polynomials using link lists

Email
 Submitted on: 1/7/2015 9:24:00 PM By: ankush gupta (from psc cd) Level: Advanced User Rating: By 2 Users Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++ Views: 8793

use of link list in multiplying two polynomials of any order

code:
Can't Copy and Paste this?
 //************************************** // Name: multiply two polynomials using link lists // Description:use of link list in multiplying two polynomials of any order // By: ankush gupta (from psc cd) // // Inputs:cofficients and the order of polynomials // // Returns:the entered polynomials and the output //************************************** #include #include #include #include class link { public: int coff,order; link *next; void getd(int a) { cout<<"enter the coff:"; cin>>coff; order=a; next=NULL; } void showd() { cout<=0;i--) //entry for poly1 { cout<<"enter coff for X^"<getd(i); if(start1==NULL) start1=newptr; else { ptr=start1; while(ptr->next!=NULL) ptr=ptr->next; ptr->next=newptr; } } for( i=or2;i>=0;i--)//entry for poly2 { cout<<"enter coff for X^"<getd(i); if(start2==NULL) start2=newptr; else { ptr=start2; while(ptr->next!=NULL) ptr=ptr->next; ptr->next=newptr; } } } void mult() { int order,coff; link *ptr3; if(start1==NULL) { cout<<"multiplication not possible"; exit(0); } ptr=start1; while(ptr!=NULL)//traversing list 1 { if(start2!=NULL) { ptr1=start2; while(ptr1!=NULL) //traversing list 2 { newptr=new link; newptr->coff=ptr->coff*ptr1->coff; newptr->order=ptr->order+ptr1->order; newptr->next=NULL; if(start3==NULL) start3=newptr; else { ptr3=start3; while(ptr3->next!=NULL) ptr3=ptr3->next; ptr3->next=newptr; } ptr1=ptr1->next; }//traversing list 2 complete } ptr=ptr->next; } //traversing list 1 complete ptr=start3; //combining similar order terms while(ptr->next!=NULL) { ptr1=ptr; while(ptr1->next!=NULL) { ptr3=ptr1; ptr1=ptr1->next; if(ptr->order==ptr1->order) { ptr->coff=ptr->coff + ptr1->coff; ptr3->next=ptr1->next; delete ptr1; ptr1=ptr3; } } ptr=ptr->next; } } void showall()//output of polynomials { ptr=start1; cout<showd(); ptr=ptr->next; if(ptr!=NULL) cout<<" + "; } ptr=start2; cout<showd(); ptr=ptr->next; if(ptr!=NULL) cout<<" + "; } ptr=start3; cout<showd(); ptr=ptr->next; if(ptr!=NULL) cout<<" + "; } } //link *start1=NULL,*start2=NULL,*ptr,*newptr; //all are pointing at null void main() { int o1,o2; clrscr(); cout<<"enter the order of polynomial 1:"; cin>>o1; cout<<"\nenter the order of polynomial 2:"; cin>>o2; enter(o1,o2); mult(); showall(); getch(); }

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)