本文整理汇总了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;
}
示例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;
}
示例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;
}
示例4: subfunction
Ordered_list<int> subfunction(Ordered_list<int> in_list)
{
in_list.insert(4);
in_list.insert(0);
return in_list;
}