⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.h

📁 链表和应用包括单链表和双链表等等。自己写的
💻 H
字号:
#ifndef KEY_H
#define KEY_H

#include "utility.h"
#include "doubly_link.h"


//Definition of a Key class:

class Key {
public:
	static int comparisons;
	Key(int x = 0);
	int the_key() const;
	//Add any constructors methods for key data.
private:
	int key;
	//Add declaration of key data members here.

	
};


Key::comparisons = 0;
int Key::the_key() const 
{
    return key;
}

// Declare overloaded comparison operators for keys.
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);

bool operator ==(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() == y.the_key();
}

bool operator >(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() > y.the_key();
}

bool operator <(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() < y.the_key();
}
bool operator >=(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() >= y.the_key();
}

bool operator <=(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() <= y.the_key();
}

bool operator !=(const Key &x, const Key &y) 
{
	
	Key::comparisons++;
	return x.the_key() != y.the_key();
}



// Definition of a Record class:
class Record {
public:
	operator Key();                //implicit conversion from Record to Key.
	//Add any constructors and methods for Record objects.
private:
	//Add data components.
};


Error_code sequential_search(const List<Record> &the_list, const Key &target, int &position)
/*Post: If the entry in the_list has key equal to target, then return success and the 
        output parameter position locates such an entry within the list.
		Otherwise return not_present and position becomes invalid.*/
{

	int s = the_list.size();
	for(position = 0; position<s; position++) {
		Record data;
		the_list.retrieve(position,data);
		if(data = target) return success;
	}
           return not_present;
}




#endif 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -