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


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

本文整理汇总了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
}
开发者ID:cliftbar,项目名称:Comp-15,代码行数:27,代码来源:main2.cpp

示例2: readFile

void readFile(SortedList &l, const char filename[])
{
    int temp;
    ifstream fin;

    fin.open(filename);
    while ( fin >> temp ) {
        l.insert(temp);
    }
    fin.close();
}
开发者ID:cliftbar,项目名称:Comp-15,代码行数:11,代码来源:main2.cpp

示例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()
开发者ID:charlie-lee,项目名称:sams_data_structure_and_algorithms,代码行数:22,代码来源:sortedList.cpp

示例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++;
					}
//.........这里部分代码省略.........
开发者ID:m-rios,项目名称:DataStructures,代码行数:101,代码来源:main.cpp


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