C++ Program:
N-number queue rotations.
[16] Write methods void Queue::lRotate(int n) and void Queue::rRotate(int n) which rotate the
queue by n-number elements.
Solution
void rRotate(int& root){
item* tmpRoot = itemArray[root];
int ogLeft = tmpRoot->left;
tmpRoot->left = itemArray[ogLeft]->right;
itemArray[ogLeft]->right = root;
root = ogLeft; //to be made the (sub)root outside the method
}
void lRotate(int& root){
item* tmpRoot = itemArray[root];
int ogRight = tmpRoot->right;
tmpRoot->right = itemArray[ogRight]->left;
itemArray[ogRight]->left = root;
root = ogRight; //to be made the (sub)root outside the method
}

C++ ProgramN-number queue rotations.[16] Write methods void Que.pdf

  • 1.
    C++ Program: N-number queuerotations. [16] Write methods void Queue::lRotate(int n) and void Queue::rRotate(int n) which rotate the queue by n-number elements. Solution void rRotate(int& root){ item* tmpRoot = itemArray[root]; int ogLeft = tmpRoot->left; tmpRoot->left = itemArray[ogLeft]->right; itemArray[ogLeft]->right = root; root = ogLeft; //to be made the (sub)root outside the method } void lRotate(int& root){ item* tmpRoot = itemArray[root]; int ogRight = tmpRoot->right; tmpRoot->right = itemArray[ogRight]->left; itemArray[ogRight]->left = root; root = ogRight; //to be made the (sub)root outside the method }