我一直在阅读Accelerated C++,我不得不说这是一本有趣的书.
在第6章中,我必须使用<algorithm>中的函数将vector <string>连接成单个字符串.我可以使用累积,但它没有帮助,因为字符串容器只能push_back字符.
int main () {
using namespace std;
string str = "Hello, world!";
vector<string> vec (10, str);
// Concatenate here?
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何将字符串连接在一起?
如何将Visual Studio 2010解决方案设为只读?
有人可以向我展示一个合并链式哈希表的删除算法示例吗?
我的插入算法是这样的:
Insert (key)
int p = hash(key)
if d[p] = NIL then
d[p] = key
next[p] = NIL
else
while next[p] != NIL
p = next[p]
endwhile
td[firstEmpty] = key
next[p] = firstEmpty
next[firstEmpty] = NIL
endif
UpdateFirstEmpty(); //sets firstEmpty to first empty slot with lowest index
endInsert
Run Code Online (Sandbox Code Playgroud)
假设表中的槽数为 13。散列函数返回Key%13
。
Keys | 5 | 18 | 16 | 15 | 13 | 31 | 26 |
Hash(key)| 5 | 5 | 3 | 2 | 0 | …
Run Code Online (Sandbox Code Playgroud) 为什么
List<Object> objectList; = some objects
List<Object> getList()
{
return objectList; //or return new List<Object>(objectList);
}
Run Code Online (Sandbox Code Playgroud)
返回一个列表,其中包含所有引用原始列表项目的项目?
谢谢.