【发布时间】:2017-07-02 04:57:45
【问题描述】:
这是我目前的程序:
#include <iostream>
#include <string>
using namespace std;
template <class type>
void display( type list[], int size );
template <class type>
void bubblesort( type list[], int size);
在我的主要功能中,我有列表。
int main()
{
const int SIZE = 5;
string nameList[SIZE] = {"Bob", "Allen", "Beth", "Zebra",
"Hamburger" };
int numberList[SIZE] = {88, 23, 74, 45, 78};
//display list 1
display(nameList, SIZE);
//display list 2
display(numberList, SIZE);
system("pause");
return 0;
}
这就是我显示列表的方式:
template <class type> //template must be included above
void display( type list[], int size )
{
for( int x = 0; x < size; x++ )
{
cout << list[x] << endl;
}
}
这是我想包含冒泡排序的地方,但我不知道如何。
template <class type>
void bubblesort( type list[], int size)
{
}
【问题讨论】:
-
请清楚您尝试过的内容以及您在哪里遇到错误
-
@RomanAnanyev 你这是什么意思?
-
@OSVALDOTORRES -- 其他一切似乎都很好 -- 你唯一做的就是输入和输出 -- 老实说,这不是一个伟大的成就.真正的测试,就是想出逻辑来计算冒泡排序,你什么都没写。
-
维基百科在bubblesort上有一个不错的页面,包括几个如何实现它的伪代码示例。