Advertisement
Stybyk

PRG 2 hodina 2

Mar 5th, 2015
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class KeyValue{
  6. private:
  7.     int key;
  8.     float value;
  9.     KeyValue * next;
  10.  
  11. public:
  12.     KeyValue(int k, float v);
  13.     float GetValue();
  14.     float SetValue();
  15.     void CreateNext(int k, float v);
  16.     KeyValue * GetNext();
  17.     ~KeyValue();
  18.  
  19. };
  20.  
  21. KeyValue::KeyValue(int k, float v){
  22.     this->key = k;
  23.     this->value = v;
  24.     this->next = NULL;
  25. }
  26.  
  27. float KeyValue::GetValue(){
  28.     return this->value;
  29. }
  30.  
  31.  
  32. KeyValue::~KeyValue()
  33. {
  34.     if (this->next != NULL){
  35.  
  36.         delete this->next;
  37.     }
  38.  
  39.  
  40. }
  41.  
  42. void KeyValue::CreateNext(int k, float v){
  43.  
  44.     if (this->next != NULL){
  45.         this->next->CreateNext(k, v);
  46.     }
  47.     else
  48.     {
  49.         next = new KeyValue(k, v);
  50.     }
  51. }
  52.  
  53.  
  54. KeyValue * KeyValue::GetNext(){
  55.  
  56.     return this->next;
  57. }
  58.  
  59. int main(){
  60.  
  61.  
  62.  
  63.  
  64.         KeyValue * c1 = new KeyValue(1, 1.5);
  65.  
  66.    
  67.  
  68.         cout << c1->GetValue() << endl;
  69.     for (int i = 0; i < 10; i++)
  70.     {
  71.    
  72.     c1->CreateNext(i, i + 0.5);
  73.    
  74.  
  75.     //cout << c1->GetNext()->GetValue() << endl;
  76.      }
  77.  
  78.  
  79.  
  80.     delete c1;
  81.  
  82.     getchar();     
  83.  
  84.  
  85.  
  86.     /*
  87.     KeyVa/lue c11(1, 1.5);
  88.     cout << c11.GetValue() << endl;
  89.  
  90.     KeyValue *c12 = new KeyValue(2, 2.5);
  91.     cout << c12->GetValue() << endl;
  92.     delete c12;
  93.  
  94.     getchar();
  95.     */
  96.     return 0;
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement