我有一些代码可以将数字数组向左旋转,但我需要它将它旋转到右边。还有其他在线代码可以向右旋转数组,但该代码只允许您在数组中间旋转数字。
我尝试过不同地减少循环&并改变其初始化的位置,但似乎没有正确的旋转方式。
预期输出:如果数组是{1, 2, 3, 4, 5, 6, 7}
。然后它应该是:{7, 1, 2, 3, 4, 5, 6}
当前输出:{2, 3, 4, 5, 6, 7, 1}
#include <iostream>
using namespace std;
/*Function to left Rotate arr[] of size n by 1*/
void leftRotatebyOne(int arr[], int n);
/*Function to left rotate arr[] of size n by d*/
void leftRotate(int arr[], int d, int n)
{
int i;
for (i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n-1; i++)
arr[i] = arr[i+1];
arr[i] = temp;
}
/* utility function to print an array */
void printArray(int arr[], int size)
{
int i;
for(i = 0; i < size; i++)
cout << arr[i] << " ";
}
/* Driver program to test above functions */
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7};
printArray(arr, 7);
leftRotate(arr, 1, 7);
cout << "___" << endl;
printArray(arr, 7);
getchar();
return 0;
}
答案 0 :(得分:1)
@objc func panned(recognizer :UIPanGestureRecognizer) {
var newAngleY :Float = 0.0
if recognizer.state == .changed {
let sceneView = recognizer.view as! ARSCNView
let touchPoint = recognizer.location(in: sceneView)
let translation = recognizer.translation(in: sceneView)
print(translation.x)
let scnHitTestResults = self.sceneView.hitTest(touchPoint, options: nil)
if let hitTestResult = scnHitTestResults.first {
let chairNode = hitTestResult.node
newAngleY = (Float)(translation.x)*(Float)(Double.pi)/180
newAngleY += chairNode.eulerAngles.y/180
chairNode.eulerAngles.y = newAngleY
}
}
else if recognizer.state == .ended {
currentAngleY = newAngleY
}
}
是这里的关键功能。其他人可以保持不变。看看它在做什么,最好用笔和纸来跟踪操作:
所以你需要做相反的事情:
例如:
leftRotateByOne