C Program Nnumber queue rotations 16 Write methods void Queu

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<KEY, VALUE>* 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<KEY, VALUE>* 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++ 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.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site