当前位置: 首页>>代码示例>>C++>>正文


C++ Ordered_list类代码示例

本文整理汇总了C++中Ordered_list的典型用法代码示例。如果您正苦于以下问题:C++ Ordered_list类的具体用法?C++ Ordered_list怎么用?C++ Ordered_list使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Ordered_list类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: delete_Collection

// Deletes a specified collection.  An error occurs if a collection with the
// specified name does not exist.
void delete_Collection(Ordered_list<Collection> &catalog)
{
	String name;
	cin >> name;
	
	Ordered_list<Collection>::Iterator it = catalog.begin();
	
	while (it != catalog.end())
	{
		if (it -> get_name() == name)
		{
			it -> clear();
			catalog.erase(it);

			num_Collections--;
			cout << "Collection " << name << " deleted" << endl;
			
			return;
		}
		
		++it;
	}

	throw Error("No collection with that name!");
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:29,代码来源:p2_main.cpp

示例2: add_Record_to_Collection

// Add a record to a collection.  An error occurs if the collection does not
// exist, an integer cannot be read, an invalid record number is specified,
// or the specified record is already a member of the specified collection.
void add_Record_to_Collection(const Ordered_list<Record *> &library, Ordered_list<Collection> &catalog)
{
	String name;
	cin >> name;
	
	Collection tmp_Collection(name);
	Ordered_list<Collection>::Iterator collection_it = catalog.find(tmp_Collection);
	
	if (collection_it == catalog.end())
	{
		throw Error("No collection with that name!");
	}
	
	int ID = get_int(cin);
	
	Record tmp_Record(ID);
	Ordered_list<Record *>::Iterator record_it = library.find(&tmp_Record);
	
	if (record_it == library.end())
	{
		throw Error("No record with that ID!");
	}

	collection_it -> add_member(*record_it);

	cout << "Member " << ID << " " << (*record_it) -> get_title() << " added" << endl;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:32,代码来源:p2_main.cpp

示例3: remove_Record_from_Collection

// Remove a specified record from a specified collection.  Errors occur if
// an integer cannot be read, there is not a record with the specified ID,
// or a collection does not exist with the specified name.
void remove_Record_from_Collection(const Ordered_list<Record *> &library, Ordered_list<Collection> &catalog)
{
	String name;
	cin >> name;
	
	Ordered_list<Collection>::Iterator it = catalog.begin();
	
	while (it != catalog.end())
	{
		if (it -> get_name() == name)
		{
			int ID = get_int(cin);
			
			Record tmp_Record(ID);
			Ordered_list<Record *>::Iterator record_it = library.find(&tmp_Record);
			if (record_it == library.end())
			{
				throw Error("No record with that ID!");
			}
			
			it -> remove_member(*record_it);
			
			cout << "Member " << ID << " " << (*record_it) -> get_title() << " deleted" << endl;
			
			return;
		}
		
		++it;
	}
	
	throw Error("No collection with that name!");
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:37,代码来源:p2_main.cpp

示例4: print

void print(const char* label, const Ordered_list<T, OF>& in_list)
{
    cout << label << " has " << in_list.size() << " items:";
	for(typename Ordered_list<T, OF>::Iterator it = in_list.begin(); it != in_list.end(); it++) {
		cout << ' ' << *it;
        }
	cout << endl;
}
开发者ID:sushaoxiang911,项目名称:ObjectOrientedProgramming,代码行数:8,代码来源:Ordered_list_String_exception_safety_demo.cpp

示例5: print_ptr

void print_ptr(Ordered_list<T>& in_list)
{
	for(typename Ordered_list<T>::Iterator it = in_list.begin(); it != in_list.end(); it++) {
		if(it != in_list.begin())	// output a leading space after the first one
			cout << ' ';
		cout << *(*it);
	}
	cout << endl;
}
开发者ID:robkeim,项目名称:random,代码行数:9,代码来源:d_ol1.cpp

示例6: binary_2

Error_code binary_2(const Ordered_list &the_list, const Key &target,
					int &position)
{
	Record data;
	int bottom = 0, top = the_list.size()-1;
	while(bottom<=top){
		position = (bottom+top)/2;
		the_list.retrieve(position,data);
		if(data==target) return success;
		if(data<target) bottom=position+1;
		else top = position-1;
	}
	return not_present;
}
开发者ID:wty1990000,项目名称:TY_repository,代码行数:14,代码来源:main.cpp

示例7: restore_All

// Restore the state of the program from a previous save.  An error occurs
// if the file could not be opened, or the file contains invalid data (which
// would be the case if the specified file has not been generated by the
// program in a previous state.
void restore_All(Ordered_list<Record *> &library_by_title, Ordered_list<Record *> &library_by_ID, Ordered_list<Collection> &catalog)
{
	String filename;
	cin >> filename;
	
	ifstream is(filename.c_str());
	if (!is)
	{
		throw Error("Could not open file!");
	}

	try
	{
		clear_data(library_by_title, library_by_ID, catalog);
		Record::reset_ID_counter();
	
		num_Records = get_int(is);

		for (int i = 0; i < num_Records; i++)
		{
			Record *record = new Record(is);
			library_by_title.insert(record);
			library_by_ID.insert(record);
		}

		num_Collections = get_int(is);

		
		for (int i = 0; i < num_Collections; i++)
		{
			Collection collection(is, library_by_title);
			catalog.insert(collection);
		}
	}
	catch (Error &error)
	{
		clear_data(library_by_title, library_by_ID, catalog);
		Record::reset_ID_counter();
		
		throw Error("Invalid data found in file!");
	}

	is.close();
	
	cout << "Data loaded" << endl;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:52,代码来源:p2_main.cpp

示例8: find_Record_using_ID

// Find a record with a speified ID, and print the information about it.
// An error occurs if an integer cannot be read, or a record with the
// specified ID does not exist.
void find_Record_using_ID(const Ordered_list<Record *> &library)
{
	int ID = get_int(cin);
	
	Record tmp_Record(ID);
	Ordered_list<Record *>::Iterator it = library.find(&tmp_Record);
	
	if (it == library.end())
	{
		throw Error("No record with that ID!");
	}

	cout << **it;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:19,代码来源:p2_main.cpp

示例9: find_Record_using_title

// Find a record with a specified title and print the information about it.
// An error occurs if a record with that name does not exist.
void find_Record_using_title(const Ordered_list<Record *> &library)
{
	String title = get_title();
	Record tmp_Record(title);
	Ordered_list<Record *>::Iterator it = library.find(&tmp_Record);
	
	if (it != library.end())
	{
		cout << **it;
	}
	else
	{
		throw Error("No record with that title!");
	}
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:19,代码来源:p2_main.cpp

示例10: clear_Catalog

// This clears the contents of the catalog.
void clear_Catalog(Ordered_list<Collection> &catalog)
{
	num_Collections = 0;
	
	catalog.clear();
	
	cout << "All collections deleted" << endl;

	return;
}
开发者ID:robkeim,项目名称:random,代码行数:11,代码来源:p2_main.cpp

示例11: print_Library

// Prints the contents of the currently library.
void print_Library(const Ordered_list<Record *> &library)
{
	int num_records = library.size();
	
	if (!num_records)
	{
		cout << "Library is empty" << endl;
		return;
	}
	
	cout << "Library contains " << num_records << " records:" << endl;
	Ordered_list<Record *>::Iterator it = library.begin();
	while (it != library.end())
	{
		cout << **it;
		++it;
	}
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:21,代码来源:p2_main.cpp

示例12: modify_Record_rating

// Change the rating of a record.  Errors occur if an integer cannot be read,
// a record with the specified ID does not exist, or the value of the new
// rating is not in the valid rating range.
void modify_Record_rating(Ordered_list<Record *> &library)
{
	int ID = get_int(cin);
	
	Record tmp_Record(ID);
	Ordered_list<Record *>::Iterator it = library.find(&tmp_Record);
	
	if (it == library.end())
	{
		throw Error("No record with that ID!");
	}
	
	int rating = get_int(cin);
	
	(*it) -> set_rating(rating);
	
	cout << "Rating for record " << ID << " changed to " << rating << endl;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:23,代码来源:p2_main.cpp

示例13: print_Catalog

// Prints the contents of the current catalog.
void print_Catalog(const Ordered_list<Collection> &catalog)
{
	int num_collections = catalog.size();
	
	if (!num_collections)
	{
		cout << "Catalog is empty" << endl;
		return;
	}
	
	cout << "Catalog contains " << num_collections << " collections:" << endl;
	Ordered_list<Collection>::Iterator it = catalog.begin();
	while (it != catalog.end())
	{
		cout << *it;
		++it;
	}
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:21,代码来源:p2_main.cpp

示例14: recursive_binary_1

//Recursive implementation without equality checking
Error_code recursive_binary_1(const Ordered_list &the_list, const Key &target,
							  int bottom, int top, int &position)
{
	Record data;
	if(bottom<top){
		int mid = (bottom+top)/2;
		the_list.retrieve(mid, data);
		if(data<target)
			return recursive_binary_1(the_list,target,mid+1,top,position);
		else
			return recursive_binary_1(the_list,target,bottom,mid,position);
	}
	else if(top<bottom)
		return not_present;
	else{
		position = bottom;
		the_list.retrieve(bottom,data);
		if(data==target) return success;
		else return not_present;
	}
}
开发者ID:wty1990000,项目名称:TY_repository,代码行数:22,代码来源:main.cpp

示例15: binary_1

//Iterative version without equality checking
Error_code binary_1(const Ordered_list &the_list,const Key &target,
					int &position)
{
	Record data;
	int bottom =0, top = the_list.size()-1;
	while(bottom<top){
		int mid = (bottom+top)/2;
		the_list.retrieve(mid,data);
		if(data<target)
			bottom = mid+1;
		else
			top = mid;
	}
	if(top<bottom) return not_present;
	else{
		position = bottom;
		the_list.retrieve(bottom,data);
		if(data==target) return success;
		else return not_present;
	}
}
开发者ID:wty1990000,项目名称:TY_repository,代码行数:22,代码来源:main.cpp


注:本文中的Ordered_list类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。