Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class Type>
  5. class cl
  6. {
  7. struct lis
  8. {
  9. lis* pre;
  10. lis* suc;
  11. Type a;
  12. } *first,*en;
  13.  
  14. public:
  15. cl(const Type b)
  16. {
  17. lis *temp=new lis;
  18. temp->a=b;
  19. first=temp;
  20. en=temp;
  21. temp->pre=NULL;
  22. temp->suc=NULL;
  23. }
  24.  
  25. void add(const Type b)
  26. {
  27. lis *temp = new lis;
  28. temp->a=b;
  29. temp->pre=en;
  30. en->suc=temp;
  31. temp->suc=NULL;
  32. en=temp;
  33. }
  34.  
  35. void print()
  36. {
  37. lis *temp = first;
  38. do
  39. {
  40. cout << temp->a <<" ";
  41. temp=temp->suc;
  42. } while(temp);
  43. cout << '\n';
  44. }
  45. };
  46.  
  47.  
  48. int main ()
  49. {
  50. cl<int> a(1);
  51. a.add(2);a.add(3);
  52. a.print();
  53.  
  54. cl<char> b('a');
  55. b.add('b');b.add('c');
  56. b.print();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement