【发布时间】:2017-09-26 15:24:26
【问题描述】:
我在下面写了一个插入排序:
int i, j;
Book temp;
for (j = 1; j < books.size(); j++) {
temp = books[j];
i = j - 1;
while (i >= 0) {
if (temp.getAuthor().compare(books[i].getAuthor()) > 0) {
break;
}
books[i +1] = books[i];
i--;
}
books[i + 1] = temp;
}
我希望能够以某种方式对其进行更改,以便我可以使用不同的因素运行它。
temp.getAuthor 也有 .getTitle 和 .getYear 无论如何都可以调整此代码,因此我也可以根据用户的选择运行它们。我正在研究模板,但不确定我是否在正确的区域?
【问题讨论】:
-
你熟悉函数指针吗?
-
可以用c++11编译吗?
标签: c++ algorithm sorting vector insertion