c++ - 我无法交出矢量图c++中带指针的变量
问题描述
我无法将变量作为向量移交。我希望你们中的一个可以帮助我。该代码应该对向量的数字进行排序,我想使用指针来防止复制。
vector<int> Heap::heapSort() {
Heap h;
vector<int> heap = { 5,39,18,0,221,15,99,22,66 };
cout << "Unsortierte Liste: ";
for (int h : heap) {
cout << h << " ";
}
cout << endl << "--------------------------------------------" << endl;
for (int k = h.parentPos(numHElements); k >= 0; k--) {
h.bubbleUpMax(heap, k, numHElements);
}
while (numHElements > 1) {
swap(heap[numHElements - 1], heap[0]);
h.bubbleUpMax(heap, 0, numHElements - 1);
numHElements--;
}
//////////////////////////////////////
cout << "Sortierte Liste: ";
for (int h : heap) {
cout << h << " ";
}
cout << endl;
return heap;
}
void Heap::bubbleUpMax(vector<int> * heap, int k, int sizeUnsorted) {
Heap h;
while (k * 2 + 1 < sizeUnsorted) {
// Linke Kindposition: k * 2+1, Rechte Kindposition: k * 2+2
int childPos = k * 2 + 1;
if ((childPos + 1 < sizeUnsorted) && (heap[childPos] < heap[childPos + 1]))
{
childPos++;
}
if (heap[h.parentPos(childPos)] < heap[childPos]) {
swap(heap[childPos], heap[k]);
k = childPos;
}
else {
break;
}
}
}
解决方案
推荐阅读
- java - 在响应中注入跟踪标头
- docker - 使用特定浏览器(最新的 chrome)和操作系统(alpine)创建预烘焙的 docker 图像
- python - 在 Keras 中使用 model.predict 时尺寸不兼容
- angular - 模块之间的角度错误循环依赖
- c++ - 如何获取对创建“this”的实例的引用?
- linux - 如何在 Linux 上运行 selenium?
- performance - 根据用户类型访问页面
- google-analytics - 应用程序的谷歌分析活动 URL 是否计算安装或打开?
- android - 将应用程序发布到 Playstore 后,Firestore 文档未正确映射
- python-3.x - 如何为 Python PyBrain 安装 modulemesh 包