Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class KeyValue{
- private:
- int key;
- float value;
- KeyValue * next;
- public:
- KeyValue(int k, float v);
- float GetValue();
- float SetValue();
- void CreateNext(int k, float v);
- KeyValue * GetNext();
- ~KeyValue();
- };
- KeyValue::KeyValue(int k, float v){
- this->key = k;
- this->value = v;
- this->next = NULL;
- }
- float KeyValue::GetValue(){
- return this->value;
- }
- KeyValue::~KeyValue()
- {
- if (this->next != NULL){
- delete this->next;
- }
- }
- void KeyValue::CreateNext(int k, float v){
- if (this->next != NULL){
- this->next->CreateNext(k, v);
- }
- else
- {
- next = new KeyValue(k, v);
- }
- }
- KeyValue * KeyValue::GetNext(){
- return this->next;
- }
- int main(){
- KeyValue * c1 = new KeyValue(1, 1.5);
- cout << c1->GetValue() << endl;
- for (int i = 0; i < 10; i++)
- {
- c1->CreateNext(i, i + 0.5);
- //cout << c1->GetNext()->GetValue() << endl;
- }
- delete c1;
- getchar();
- /*
- KeyVa/lue c11(1, 1.5);
- cout << c11.GetValue() << endl;
- KeyValue *c12 = new KeyValue(2, 2.5);
- cout << c12->GetValue() << endl;
- delete c12;
- getchar();
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement