翻转
2015-07-10 20:32
204 查看
1.翻转整型数字(翻转前为n,翻转后为t)
while(n) { t=t*10+n%10; n/=10; }
2.[b]翻转数组[/b]
void rever_char(char c[],int n) { char temp; int i,j = n-1,m = (n-1)/2; for(i = 0; i <= m; i++) { j = n-1-i; temp = c[i]; c[i] = c[j]; c[j] = temp; } }
3,指针[b]翻转数组[/b]
void reversal(int *a,int len) { if (len<2) return; //用指针实现 int *left=a,*right=a+len-1,temp; do { temp = *left; *left = *right; *right = temp; }while (++left < --right); /*while (left++ <= right--)//指针的第二种写法 { temp = *left; *left = *right; *right = temp; } //用数组实现 int end=len/2,tmp,j; for (int i=0;i<end;++i) { tmp = a[i]; j = len -1 - i; a[i] = a[j]; a[j] = tmp; }*/ }
转载请注明出处:/article/7660356.html
相关文章推荐
- 数组&&函数数组
- C语言 printf
- 查询复杂sql的表的大小
- java底层的深入理解——————堆栈
- B树、红黑树简单概念
- 关于堆,栈等内存的使用
- 操作符重载:什么时候返回引用
- Java变量&&简单程序流程&&循环
- Android 自己动手编译android源码
- 编程习惯
- 转载邮件失败!javax.mail.AuthenticationFailedException: 535 Error: authentication
- 鼠标指针变图片
- Java安装
- dedecms织梦出现“Upload filetype not allow”原因和解决方案
- 树莓派自动登陆
- spring中context:property-placeholder/元素
- [LeetCode][Java] Remove Duplicates from Sorted Array
- iOS网络协议----HTTP/TCP/IP浅析
- Java的安全学习(包括加密,数字签名,证书和认证)
- 如何使用AutoIT完成单机测试