Embed presentation
Download to read offline
![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
}](https://image.slidesharecdn.com/cprogramn-numberqueuerotations-230704163823-c09f596c/85/C-ProgramN-number-queue-rotations-16-Write-methods-void-Que-pdf-1-320.jpg)
The document describes a C++ program that implements methods for rotating a queue by a specified number of elements. It includes the implementation of two methods, lrotate and rrotate, which adjust the queue structure by updating pointers accordingly. The provided code snippets demonstrate how to manipulate the queue's root to achieve the desired rotations.
![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
}](https://image.slidesharecdn.com/cprogramn-numberqueuerotations-230704163823-c09f596c/85/C-ProgramN-number-queue-rotations-16-Write-methods-void-Que-pdf-1-320.jpg)