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


C++ Ordered_list::insert方法代码示例

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


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

示例1: 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

示例2: add_Record

// Add a record to the library.  An error occurs if the library already has
// a record with the specified name.
void add_Record(Ordered_list<Record *> &library_by_title, Ordered_list<Record *> &library_by_ID)
{
	String medium;
	cin >> medium;
	
	String title = get_title();
	
	Record tmp_Record(title);
	if (library_by_title.find(&tmp_Record) != library_by_title.end())
	{
		throw Error("Library already has a record with this title!");
	}
	
	Record * record = new Record(medium, title);
	
	library_by_title.insert(record);
	library_by_ID.insert(record);
	
	num_Records++;
	
	cout << "Record " << record -> get_ID() << " added" << endl;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:26,代码来源:p2_main.cpp

示例3: add_Collection

// Add collection with a specified name.  An error occurs if the catalog
// already has a collection with the specified name.
void add_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)
		{
			throw Error("Catalog already has a collection with this name!");
		}
		++it;
	}

	catalog.insert(Collection(name));
	
	num_Collections++;
	
	cout << "Collection " << name << " added" << endl;
	
	return;
}
开发者ID:robkeim,项目名称:random,代码行数:25,代码来源:p2_main.cpp

示例4: subfunction

Ordered_list<int> subfunction(Ordered_list<int> in_list)
{
	in_list.insert(4);
	in_list.insert(0);
	return in_list;
}
开发者ID:sushaoxiang911,项目名称:ObjectOrientedProgramming,代码行数:6,代码来源:Ordered_list_demo.cpp


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