using namespace std;
void swap_first_last(queue& q) {
// Check if the queue is empty.
if (q.empty()) {
return;
}
// Store the first element in a temporary variable.
int first_element = q.front();
// Remove the first element from the queue.
q.pop();
// Enqueue the first element at the end of the queue.
q.push(first_element);
// Remove the last element from the queue.
q.pop();
// Enqueue the temporary variable at the beginning of the queue.
q.push(first_element);
}
int main() {
// Create a queue.
queue q;
// Enqueue some elements.
q.push(1);
q.push(2);
q.push(3);
// Swap the first and last elements.
swap_first_last(q);
// Print the queue.
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
cout << endl;
return 0;
}