本文整理汇总了C++中ListItem::getContent方法的典型用法代码示例。如果您正苦于以下问题:C++ ListItem::getContent方法的具体用法?C++ ListItem::getContent怎么用?C++ ListItem::getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListItem
的用法示例。
在下文中一共展示了ListItem::getContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: last
List::List(const List &other):
first(nullptr), last(nullptr), currentSize(0), def(0)
{
for (ListItem *item = other.first; item != nullptr; item = item->getNext()) {
appendElement(item->getContent());
}
}
示例2: last
List::List(const List& other):
first(nullptr), last(nullptr), currentSize(0)
{
// Copy list item-wise to avoid having two lists pointing at the same list items
for (ListItem *item = other.first; item != nullptr; item = item->getNext()) {
appendElement(item->getContent());
}
}
示例3:
int& List::getNthElement(int n) {
int index = n;
ListItem* p = first;
// iterate over elements
while (index-- > 0) {
p = p->getNext();
}
return p->getContent();
}
示例4: out_of_range
int &List::getNthElement(int n) {
if (currentSize >= n + 1 && n >= 0) {
ListItem* tmp = first;
for (int i = 0; i < n; i++) {
tmp = tmp->getNext();
}
return tmp->getContent();
}
else
throw std::out_of_range("List index out of range");
}
示例5: deleteAt
int List::deleteAt(int pos) {
if (pos <= 0)
return deleteFirst();
else if (pos >= getSize())
return deleteLast();
else {
ListItem *del = first;
while (pos-- > 0) {
del = del->getNext();
}
int val = del->getContent();
delete del;
currentSize--;
return val;
}
}
示例6: deleteAt
int List::deleteAt(int pos) {
if (pos <= 0) {
return deleteFirst();
}
else if (pos >= currentSize - 1) {
return deleteLast();
}
else {
int index = pos;
ListItem* p = first;
// iterate over elements
while (index-- > 0) {
p = p->getNext();
}
int content = p->getContent();
delete p;
--currentSize;
return content;
}
}