sort 对一数组排序
int main()
{
int a[5]={-1,1,10,2,5};
sort(a+1,a+5);
for(int i=1;i<5;i++)
printf("%d ",a[i]);
printf("/n");
int b[5]={0,1,10,2,5};
sort(b+1,b+4);
for(int i=1;i<5;i++)
printf("%d ",b[i]);
getchar();
}
显然结果是
1 2 5 10
1 2 10 5
追究其sort(v.begin,v.end)
而在STL里 v.end 是个不存在的值.
故而假设 a[n+1] 我要对下标1---n进行排序也就是n个数进行排序则应当写为sort(a+1,a+n+1)
而我在北大acm上1700题用sort(a+1,a+n)是Accept的,而sort(a+1,a+n+1)也是Accept.
唉...不知是否其数据有问题乎.