我们在考虑数据前后交换的问题时,若middle指针的位置小于中位数,即后方移动的数据多于前方,故需要将前方数据先进行备份,再将后方数据移动至front指针位置,最后将先前备份的数据拷贝回剩余的数据结构中。
这是一种通用的解决方案。着重理解rotate1方法。注意内存位置的移动和计算(核心思想)。memmove方法与memcpy方法相似,不同的是,目标和源 有重叠时,其能够正常工作。
#include <iostream> #include <string.h> using namespace std; void rotate1(void *front, void *middle, void *end) { int front_size = (char *)middle - (char *)front; int back_size = (char *)end - (char *)middle; // char buffer[front_size]; char *buffer = (char *) malloc(front_size); memcpy(buffer, front, front_size); memmove(front, middle, back_size); memcpy((char *)end - front_size, buffer, front_size); //also like follow //memcpy((char *)front + ((char *)end - (char *)middle), temp, (char *)middle - (char *)front); free(buffer); } void rotate2(void *front, void *middle, void *end) { char *temp = (char *) malloc((char *)middle - (char *)front); memcpy(temp, front, (char *)middle - (char *)front); memmove(front, middle, (char *)end - (char *)middle); memcpy((char *)front + ((char *)end - (char *)middle), temp, (char *)middle - (char *)front); free(temp); } int main() { int a[7] = {1, 2, 3, 4, 5, 6, 7}; rotate1(&a[0], &a[2], &a[6]); int i=0; for(; i < 7; i++) { cout << a[i] << endl; } getchar(); return 0; }
相关推荐
此apache mod_log_rotate 是win32下vc9版的apache 日志文件管理工具。 使用: 复制mod_log_rotate.so到 Apache2/modules 确保你的系统安装了 Visual C++ 2008 Redistributable (可从这里下载:) ...
rotate旋转
Rotate.zipscratch2.0 3.0编程项目源文件源码经典游戏案例素材源代码Rotate.zipscratch2.0 3.0编程项目源文件源码经典游戏案例素材源代码Rotate.zipscratch2.0 3.0编程项目源文件源码经典游戏案例素材源代码Rotate....
jquery.rotate.min.js 版本VERSION: 2.3
旋转图像的c 代码,正对bmp格式, 无插值,
Laravel开发-laravel-logs-rotate 使用压缩旋转文件日志
前端开源库-winston-daily-rotate-fileWinstonDaily Rotate文件,Winston每天记录到一个旋转文件的传输。
Rotate image without degrading it
js旋转插件jquery.rotate
rotate image matlab
Jquery 的动画转动效果 效果很好 用起来非常方便
三维操作,例如zoom rotate pan的操作,通过数学公式的计算来精确求的所需的量,这个程序主要是在交互操作方面vs2008 + diretx,但是用opengl也是可以的,原理是相同的,在程序中我用了右手坐标系,这样opengl可以很...
css3-rotate实现超炫环形旋转特效是一款采用css3 rotate实现的蓝色环形旋转特效代码。
yuv420sp顺时针旋转90°
编程开发-综合控件-jquery rotate插件 官方版.zip
最新的rotateimage图像处理组件,实现图片以中心/非中心 作为旋转焦点进行任意角度的旋转 内有Demo可供参考学习 a component similar to TImage with the ability to show the image rotated at an arbitrary ...
Rotate Layout Custom layout that can rotate it's view Usage In your layout file add <!-- Specify rotate angle here --> Voila! Your layout will be rotated 90 degrees. Download compile '...
实现控件绕轴旋转,既可以拖拽控件旋转,也可以让其自动旋转。稍作加工即可实现比较实用的效果
jquery中一个可以旋转的图片的js,Jquery 的动画转动效果 效果很好 用起来非常方便,有兴趣的小伙伴可以下载下来,进行开发,用的这个js,代码开发也很容易
Android动画效果translate、scale、alpha、rotate详解