选择排序算法不知道出什么问题了

求助,不知道算法有什么问题
谢谢了

#ifndef PCH_H
#define PCH_H

// TODO: 添加要在此处预编译的标头
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#endif //PCH_H

using namespace std;

#include "pch.h"

template <typename T>

void sort(T arr[]) {
    int length = sizeof(arr) / sizeof(T);   //数组长度
    T temp; //临时
    T i, j; //自变量
    T max;  //交换时选取的最大值,开始时应赋予第一个数的值
    for (i = 0; i < length; i++) {
        max = arr[i];
        for (j = i + 1; j < length; j++) {
            if (arr[j] > max) {
                temp = max;
                max = arr[j];
                arr[j] = temp;
            }
        }
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}

int main() {
    int a[10];
    for (int i = 0; i <= 9; i++)
        cin >> a[i];
    sort(a);
    for (int i = 0; i <= 9; i++)
        cout << a[i];
}

函数里数组退化为指针,不能用sizeof取长度
你的排序算法也没有写对

// Q768219.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>

using namespace std;

template <typename T>

void sort(T arr[], int n) {
    int length = n;   //数组长度
    T temp; //临时
    int i, j; //自变量
    int max;  //交换时选取的最大值,开始时应赋予第一个数的值
    for (i = 0; i < length; i++) {
        max = i;
        for (j = i + 1; j < length; j++) {
            if (arr[j] > arr[max]) {
                max = j;
            }
        }
        temp = arr[i];
        arr[i] = arr[max];
        arr[max] = temp;
    }
}

int main() {
    int a[10];
    for (int i = 0; i <= 9; i++)
        cin >> a[i];
    sort(a, 10);
    for (int i = 0; i <= 9; i++)
        cout << a[i] << " ";
}

4 5 8 1 5 3 7 11 2 4
11 8 7 5 5 4 4 3 2 1 Press any key to continue . . .

问题解决请点采纳