Reference Book: 《Data Structures and Program Design in C++》
---------------------------------------------------------------------------------------------------------------------------------------------------
1. Double_Linked_List见文章Double_Linked_List代码实现
2. (1) Record.h
#ifndef RECORD_H
#define RECORD_H
#include <iostream>
using namespace std;
typedef int Key_type;
typedef Key_type Record_type;
class Key
{
private:
Key_type key;
public:
static Key_type comparisons;
Key(int x=0);
Key_type the_key()const;
};
bool operator == (const Key &x, const Key &y);
bool operator > (const Key &x, const Key &y);
bool operator < (const Key &x, const Key &y);
bool operator >= (const Key &x, const Key &y);
bool operator <= (const Key &x, const Key &y);
bool operator != (const Key &x, const Key &y);
ostream &operator << (ostream &output, Key &x);
/*
class Record
{
public:
Record(int x=0, int y=0);
int the_key()const;
protected:
private:
int key;
int other;
};
*/
#endif // RECORD_H
2. (2) Record.cpp
#include "Record.h"
int Key::comparisons = 0;
Key::Key(int x)
{
key = x;
}
Key_type Key::the_key()const
{
return key;
}
bool operator == (const Key &x, const Key &y)
{
Key::comparisons++;
return x.the_key()==y.the_key();
}
bool operator > (