【发布时间】:2019-01-03 03:20:17
【问题描述】:
我正在尝试在链表上实现选择排序。我希望它直接在链表上执行,而不是复制,使用节点指针而不是我在这里粘贴的数组索引方法:
void listClass::selectionsort(int array[], int size)
{
int startscan, minIndex, minValue;
for (startscan = 0; startscan < (size - 1); startscan++)
{
minIndex = startscan;
minValue = array[startscan];
for (int index = startscan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startscan];
array[startscan] = minValue;
}
}
如何调整这个函数来接受我的链表?并排序?我也不想使用任何类型的 STL 容器。
【问题讨论】:
-
否定,我正在为软件工程实习准备面试练习题
标签: c++ sorting linked-list selection