i would like your help with this question I have, I need to write a C++ function that inputs a queue as parameter and checks whether the contents in the queue are in sorted order (such that the front element is smallest). A BOOLEAN
value should be returned accordingly. Assuming that there is no duplicated element in the queue.
I am trying to get my head around the concept of sorting, so any help would be appreciated, here is what I have tried so far:
#include "stdafx.h"
#include <iostream>
#include <queue>
using namespace std;
bool is_Sorted(queue<int> q) {
int my_front = q.front();
int my_back = q.back();
if (my_front==my_back) {
return true;
}
if (my_front+1>my_front) {
return true;
}
}
int main()
{
queue <int> q;
q.push(3);
q.push(4);
q.push(5);
q.push(6);
q.push(7);
is_Sorted(q);
return 0;
}