本文整理汇总了C++中SortedList::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ SortedList::insert方法的具体用法?C++ SortedList::insert怎么用?C++ SortedList::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList::insert方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_findmax
void test_findmax()
{
#if FINDMAX
printf("Running test_findmax\n");
SortedList l1, l2;
int m1, m2;
readFile(l1, file1);
readFile(l2, file2);
m1 = l1.findMax();
m2 = l2.findMax();
cout << "list is ";
l1.print();
printf("Your max is %d, should be 78\n", m1);
cout << "list is ";
l2.print();
printf("Your max is %d, should be 42\n", m2);
SortedList eric;
eric.insert(-100);
eric.insert(-101);
eric.insert(-102);
m1 = eric.findMax();
cout << "list is ";
eric.print();
printf("Your max is %d, should be -100\n", m1);
#endif
}
示例2: readFile
void readFile(SortedList &l, const char filename[])
{
int temp;
ifstream fin;
fin.open(filename);
while ( fin >> temp ) {
l.insert(temp);
}
fin.close();
}
示例3: main
int main()
{
SortedList* sl = new SortedList();
sl->insert(1);
sl->insert(50);
sl->displayList();
sl->insert(3);
sl->insert(20);
sl->insert(7);
sl->displayList();
while(sl->removeFirst())
sl->displayList();
delete sl;
return 0;
} // end main()
示例4: main
int main()
{
#define HELP "Usage: $ palindrome [parameter]\nWhere: parameter is one of:\n\t\t-h (help)\n\t\t-k (read from keyboard)\n\t\t-f file (read from file)\n\t\t-d letter (remove all palindromes which start by this letter)\n\t\t-s (show data)\n\t\t-q (exit)\n";
string input ("\0");
string original ("\0");
string command;
SortedList list;
//always print the help at the begin
cout << HELP;
do
{
//print a new prompt until -q
cout << "$ palindrome ";
//read command
getline(cin, command, '\n');
//create our own argv
vector<string> myArgv;
istringstream iss(command);
string token;
while(getline(iss, token, ' '))
{
myArgv.push_back(token);
}
//create our own argc
int myArgc = myArgv.size();
//main method
if (myArgc == 1)
{
if (myArgv[0] == "-h")
{
cout << HELP;
}
else if (myArgv[0] == "-s")
{
//show in the screen the number of queues in the list, the total number of palindromes in each queue and their starting letter
cout << list.toString() << endl;
}
else if (myArgv[0] == "-k")
{
int i = 0;
cout << "(-q to exit)" << endl;
do
{
cout << "(" << i << ") "; i++;
getline(cin, original, '\n');
input = rmSpace(original);
if (isPalindrome(input))
{
//insert original in the list
list.insert(original);
cout << "Palindrome inserted!" << endl;
}
else
if (original!="-q")
cout << "This is not palindrome, then not inserted!" << endl;
}
while(original!="-q");
}
else
{
if (myArgv[0] != "-q")
{
cout << "Paremeter unknown " << myArgv[0] << endl;
}
}
}
else if (myArgc == 2)
{
if (myArgv[0] == "-f")
{
int cont0 = 0, cont1 = 0;
ifstream inputFile (myArgv[1]);
if(inputFile.is_open())
{
string tmp;
while(getline(inputFile, tmp))
{
input = rmSpace(tmp);
if (isPalindrome(input))
{
//insert tmp in the list
list.insert(tmp);
cont1++;
}
else
cont0++;
}
//.........这里部分代码省略.........