ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Tuesday 26 April 2016

CSE1002:BONUS:Generic Right Shift

CSE1002 Generic Right Shift    

Given a set of 'n' elements and 'r', write a generic function to right shift the set of elements by 'r' position. If the elements are to moved to position greater than 'n' then wrap the shift process to the beginning of the collection. For example, if the set of five elements are 1,7,8,9,12 and value of 'r' is 3 then the set of elements would be 8, 9, 12, 1, 7.

PSUEDOCODE:

DEFINE right_Shift(T a[],int n,int r)
for i->0 to r
   T temp = a[n-1];
   for j->n-2 to 0
       a[j+1]=a[j];
   end for
   a[0]=temp;
end for
end definition



CODE:
#include<iostream>
using namespace std;
template <class T>
void right_Shift(T a[],int n,int r)
{
for(int i=0;i<r;i++)
 {
   T temp = a[n-1];
   for(int j=n-2;j>=0;j--)
       a[j+1]=a[j];
   a[0]=temp;
 }
}

No comments:

Post a Comment