#include
using namespace std;
int* order (int* const list,int size);
int main()
{ int size;
cout<<"数组的大小为:"< cin>>size;
int* list =new int [size];
cout<<"请输入数组元素:"<<endl;
for (int i=0;i<size;i++)
{cin>>list[i];}
for(int j=0;j<size;j++)
{cout<<&list[j]<<"为"<<list[j]<<"所对应的指针指向的地址."<<endl;}
order(list,size);
cout<<"按升序输出数组元素为:"<<endl;
for (int k=0;k<size;k++)
{cout<<*(list+k)<<" ";
delete []list;
return 0;
}
int* order (int* const list,int size)
{
for(int l=0;l { for (int j=l+1;j { if(list1[l]>list1[j])
{
int tem;
tem=list1[l];
list1[l]=list1[j];
list1[j]=tem;
}
}
}
return list;
}
编译时老是显示:
[Error] a function-definition is not allowed here before '{' token
[Error] expected '}' at end of input
没太看明白你的CODE,
cout<<"按升序输出数组元素为:"<<endl;
for (int k=0;k<size;k++)
{cout<<*(list+k)<<" "; 这里为什么没有“}”
能不能写得有indent
这个里面在粘贴过来好像有点小问题,嘻嘻,应该没关系吧
仅供参考
#include <iostream>
using namespace std;
int* order (int* const list,int size);
int main()
{
int size;
cout<<"数组的大小为:"< cin>>size;
int* list =new int [size];
cout<<"请输入数组元素:"<<endl;
for (int i=0;i<size;i++)
{cin>>list[i];}
for(int j=0;j<size;j++)
{cout<<&list[j]<<"为"<<list[j]<<"所对应的指针指向的地址."<<endl;}
order(list,size);
cout<<"按升序输出数组元素为:"<<endl;
for (int k=0;k<size;k++) // 遍历
{
cout<<*(list+k)<<" ";
}
delete []list;
return 0;
}
int* order (int* const list1,int size)
{
for(int l=0;l < size;l++) {
for (int j=l+1;j<size;j++){
if(list1[l]>list1[j])
{
int tem;
tem=list1[l];
list1[l]=list1[j];
list1[j]=tem;
}
}
}
return list1;
}
初学者的话,建议下载一个好用一点的IDE,各种常见的语法错误都会提示出来。不知道你用的是什么,c的话个人感觉vs比较好,也可以查查怎么打开你的编辑器的语法提示。