Advertisement
Coriic

Dla Irminy

Jun 21st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Animal{
  4. public:
  5. virtual Animal* copy()const =0;
  6. };
  7.  
  8. class Dog:public Animal{
  9. public:
  10. Animal* copy()const{
  11. return new Dog(*this);
  12. }
  13. };
  14.  
  15. class Cat: public Animal{
  16. public:
  17. Animal* copy()const{
  18. return new Cat(*this);
  19. }
  20. };
  21.  
  22. class Frog: public Animal{
  23. public:
  24. Animal* copy() const{
  25. return new Frog(*this);
  26. }
  27. };
  28.  
  29. class AnimalWezel{
  30. public:
  31. AnimalWezel* next;
  32. Animal* wsk;
  33. };
  34.  
  35. class AnimalList{
  36. private:
  37. AnimalWezel* begin;
  38. AnimalWezel* end;
  39. public:
  40. AnimalList(): begin(0), end(0){}
  41. ~AnimalList();
  42. void add(Animal* a);
  43. AnimalList(const AnimalList&);
  44. AnimalList& operator=(const AnimalList&);
  45. };
  46.  
  47. AnimalList::~AnimalList() {
  48. AnimalWezel* it;
  49. while(begin=0){
  50. it=begin;
  51. begin=begin->next;
  52. delete(it->wsk);
  53. delete(it);
  54. }
  55. begin=0;
  56. end=0;
  57. }
  58. void AnimalList::add(Animal* a){
  59. AnimalWezel* tmp;
  60. if(begin=0){
  61. begin=tmp;
  62. end=tmp;
  63. tmp->next=0;
  64. }
  65. else{
  66. end->next=tmp;
  67. tmp->next=0;
  68. end=tmp;
  69. }
  70. tmp->wsk=a;
  71. }
  72.  
  73. AnimalList::AnimalList(const AnimalList& copy1) {
  74. AnimalWezel* it=copy1.begin;
  75. while(it!=0){
  76. this->add(it->wsk->copy());
  77. it=it->next;
  78. }
  79. }
  80.  
  81. AnimalList& AnimalList::operator=(const AnimalList& copy1){
  82. AnimalWezel* it;
  83. while(begin=0){
  84. it=begin;
  85. begin=begin->next;
  86. delete(it->wsk);
  87. delete(it);
  88. }
  89. begin=0;
  90. end=0;
  91. it=copy1.begin;
  92. while(it!=0){
  93. this->add(it->wsk->copy());
  94. it=it->next;
  95. }
  96. return (*this);
  97. }
  98.  
  99. int main(){
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement