I'm trying to implement a function for shifting an array of objects to the right of the array. All i found in the Internet is implementation of circular shifts but that is not what I'm looking for. I want to shift the elements to the right if theres actually empty space on its right. suppose you created an array of object Packet, and its of size 10
Packet* a[] = { p4 , p3 , p2 , p1, null, null, null, null, null, null }
the shifting function would just shift everything to the right
{ null ,p4 , p3 , p2 , p1, null, null, null, null, null }
and in the case of having an element at the end of the array
{ p10, p9, p8, p7 ,p6 ,p5 ,p4 , p3 , p2 , p1}
the function just wouldn't shift anything.
{ p4 , p3 , p2 , p1, null, null, null, null, null, null }
my idea of implementation is to copy the array into a temp one, erase everything on the original array, and then copy into it but starting from position [1] and not position [0]. but this doesn't seem very efficient.
any other ideas?
std::rotate?