本文整理汇总了C++中SortedList::getFirst方法的典型用法代码示例。如果您正苦于以下问题:C++ SortedList::getFirst方法的具体用法?C++ SortedList::getFirst怎么用?C++ SortedList::getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList::getFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inheritanceClassDemo
void inheritanceClassDemo()
{
ListItem *item;
/* Lets see how the items are created. Please use step into the
* see how the next instruction creates an element.
*/
IntListItem intItem0(0);
/* Now lets see it create a different type of item. Please use
* step into the see this go to the FloatListItem constructor.
*/
FloatListItem floatItem0(1.0);
/* Now we will start adding items to lists. We will create one
* list that may contain either Integers or Floats.
*/
List linkedList;
/* Let's start adding to the list. Items will be added to the end
* of the list.
*/
linkedList.add(intItem0);
linkedList.add(intItem1);
linkedList.add(intItem2);
linkedList.add(floatItem0);
linkedList.add(floatItem1);
linkedList.add(floatItem2);
/* Display the contents of the linked list. Notice a mixture of integers
* and floating numbers are inserted into the list. The "displayValue"
* function for these items will be resolved at runtime since "item" is a
* pointer to the base class ListItem.
*/
for (item = linkedList.getFirst();
item != 0;
item = item->getNext())
{
item->displayValue();
}
/* Remove the items from the list.
*/
while (linkedList.getFirst() != 0)
{
linkedList.remove(*(linkedList.getFirst()));
}
/* If you stepped into during the adds, you would have seen how
* that the member function "add" for List was called. Now we will
* create another list that is sorted using SortedList which
* derives from List, but changes the add function to sort the
* list.
*
* NOTE: We will be using the overridded member function "compare"
* in the ListItem for each of the derived classes
* "IntListItem" and "FloatListItem". Since these cannot be
* compared between each other we will create two classes;
* one for integers and one for floats.
*/
SortedList intList;
SortedList floatList;
/* Add the first items. Please step into the next instructions to
* see how the "compare" member function get called for
* IntListItem and FloatListItem. Also notice how the "add" member
* function get called in the SortedList Class.
*/
intList.add(intItem1);
floatList.add(floatItem1);
/* Now lets add something to the front of the list.
*/
intList.add(intItem0);
floatList.add(floatItem0);
/* Now to the end of the list.
*/
intList.add(intItem3);
floatList.add(floatItem3);
/* Now in the middle.
*/
intList.add(intItem2);
floatList.add(floatItem2);
/* Display the contents of the sorted integer linked list.
*/
for (item = intList.getFirst();
item != 0;
item = item->getNext())
{
item->displayValue();
}
/* Display the contents of the sorted floating linked list.
*/
for (item = floatList.getFirst();
item != 0;
//.........这里部分代码省略.........