Problem C: C语言习题 整数排序
来源:互联网 发布:阿里云cdn流量包怎么用 编辑:程序博客网 时间:2024/05/12 03:10
Problem C: C语言习题 整数排序
Description
用指向指针的指针的方法对n个整数排序并输出。要求将排序单独写成一个函数。整数和n在主函数中输入。最后在主函数中输出。
Input
n和n个整数
Output
排序后的整数
Sample Input
54 3 2 1 5
Sample Output
1 2 3 4 5
HINT
主函数已给定如下,提交时不需要包含下述主函数
/* C代码 */
int main()
{
void sort(int **,int );
int i,n,data[20],**p,*pstr[20];
scanf("%d",&n);
for (i=0; i<n; i++)
pstr[i]=&data[i];
for (i=0; i<n; i++)
scanf("%d",pstr[i]);
p=pstr;
sort(p,n);
for (i=0; i<n; i++)
printf("%d ",*pstr[i]);
return 0;
}
/* C++代码 */
int main()
{
void sort(int **,int );
int i,n,data[20],**p,*pstr[20];
cin>>n;
for (i=0; i<n; i++)
pstr[i]=&data[i];
for (i=0; i<n; i++)
cin>>*pstr[i];
p=pstr;
sort(p,n);
for (i=0; i<n; i++)
cout<<*pstr[i]<<" ";
return 0;
}
void sort(int **p,int n){ int i,j,*temp; for(j=0;j<n-1;j++) for(i=0;i<n-j;i++) if(**(p+i)>**(p+i+1)) {temp=*(p+i); *(p+i)=*(p+i+1); *(p+i+1)=temp; }} int main(){ void sort(int **,int ); int i,n,data[20],**p,*pstr[20]; scanf("%d",&n); for (i=0; i<n; i++) pstr[i]=&data[i]; for (i=0; i<n; i++) scanf("%d",pstr[i]); p=pstr; sort(p,n); for (i=0; i<n; i++) printf("%d ",*pstr[i]); return 0;}
0 0
- Problem C: C语言习题 整数排序
- Problem C: C语言习题 整数排序
- Problem C: C语言习题 整数排序
- Problem C: C语言习题 整数排序
- C语言习题 整数排序
- YTU 2427: C语言习题 整数排序
- YTU C语言习题 整数排序
- oj2427: C语言习题 整数排序
- Problem C: C语言习题 等长字符串排序
- Problem E: C语言习题 等长字符串排序
- Problem F: C语言习题 不等长字符串排序
- Problem E: C语言习题 等长字符串排序
- Problem F: C语言习题 不等长字符串排序
- Problem D: C语言习题 不等长字符串排序
- Problem C: C语言习题 字符串长度
- Problem C: C语言习题 字符串长度
- Problem A: C语言习题5.9--整数n和m之间的素数个数
- Problem D: C语言习题 字符串比较
- scp或ssh登录时遇到Host key verification failed问题的解决方法
- Redis 相关学习
- Python Collections Counter
- VS2005 添加lib 的方法
- PHP class
- Problem C: C语言习题 整数排序
- w25q128 优化读写函数
- ORACLE 数据类型总结
- 【南理oj】991 - Registration system(STL - map & string)
- ORACLE中%TYPE和%ROWTYPE的使用
- C语言命名规范
- LeetCode题解-83-Remove Duplicates from Sorted List
- Java内部类
- dd