View Single Post
Join Date: Nov 2008
Posts: 32
Reputation: Ahmed_I is an unknown quantity at this point 
Solved Threads: 1
Ahmed_I Ahmed_I is offline Offline
Light Poster

Re: Genreic Double Linked List Using Templates

 
0
  #8
Nov 22nd, 2008
This is the modified function
  1. template <class type> void append(node<type>** l,const type& elem)
  2. {
  3. if(*l==NULL)
  4. insert_first(&*l,elem);
  5. else
  6. {
  7. node<type>*temp=*l;
  8. node<type> *Q=new node<type>;
  9. Q->data=elem;
  10. while(temp->next!=NULL)
  11. {
  12. temp=temp->next;
  13. }
  14. temp->next=Q;
  15. Q->prev=temp;
  16. }
  17. }


and this is the test in main
  1. int main(int argc, char** argv)
  2. {
  3. node<int>* q=NULL;//Create Empty Pointer that Will point to the Head of the List
  4. insert_first(&q,2);
  5. append(&q,5); //Here is the test
  6. print_l(q);
  7. system("PAUSE");
  8. return 0;
  9. }
Reply With Quote