Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. #include<iostream>
  3. #include<array>
  4. using namespace std;
  5.  
  6. struct term{
  7.         term(int data, term* link=NULL):data(data), next(link){}
  8.         int data;
  9.         term* next;
  10. };
  11. term*& genTerms(int[], term*&, int);
  12. int main(){
  13.         term* head_A= NULL;
  14.         int aPoly[4];
  15.         for(int i = 0; i<5; i++){
  16.                 aPoly[i] = i+1;
  17.         }
  18.         head_A = genTerms(aPoly, head_A, 4);
  19.         int count = 0;
  20.         for(term* iter = head_A; iter!=NULL; iter->next){
  21.                 count ++;
  22.                 cout<< "term #"<<count<<" is ==== " <<iter->data <<endl;
  23.                 iter=iter->next;
  24.         }
  25. }
  26. term*& genTerms(int coef[], term*& head, int i){
  27.         head = new term(coef[i], head);
  28.         if(i<=0) return head;
  29.         return genTerms(coef, head, i-1);      
  30. }