Hi;

need your help ,
now i want a hint for this question to know how to solve it :

template <class T>
void sortqueu(queueType <T> & q);

this function is to sort all elements of that queue . using queue operation only (it is not a member function ) .

i tried to store the first element in a temp. than copare it with the second one , until the end of the queue .

but i discover later that all the element will be delete !

what to do it ? Help me !!

This is a special operation that can't easily be done using just the basic queue operations. So you should make it a non-member friend function and sort the internal storage structure.

commented: Way to totally ignore the requirements of the homework assignment +6

This is a special operation that can't easily be done using just the basic queue operations. So you should make it a non-member friend function and sort the internal storage structure.

can you explain more,
i do not understand it ..

Make the sort a friend function or member function of queueType. That way you can sort the array or linked list or whatever it is you use inside the class.

Make the sort a friend function or member function of queueType. That way you can sort the array or linked list or whatever it is you use inside the class.

No , we can not solve it as a member function ,the question say this
we must solve it as non-member function

Now , i am thinking to create an array with length equal to the queue length ;
then put the first element from the Q in the array , and since we can transfer and make shifting in Array , i can compare each element in the Q with others in array , then sort them by shifting .

>we must solve it as non-member function
A friend is a non-member function. :icon_rolleyes:

>we must solve it as non-member function
A friend is a non-member function. :icon_rolleyes:

Oh, really :icon_wink:

if it is , can we use what does the member function can use

i mean the data member ;

sorry but i forgot these kind of functions and what to do :$

and what about my prevous way to solve it?

>can we use what does the member function can use
Don't make me beat you in the name of grammar.

>sorry but i forgot these kind of functions and what to do
Add this line to your class definition:

template <typename U> friend void sortqueue(queueType <U> & q);

Now sortqueue can access the private members of queueType and you can directly sort the data structure that it uses internally.

>and what about my prevous way to solve it?
If all you have is a basic queue, where the only operations are is_empty, enqueue, and dequeue, your only reasonable option is to empty the queue into a more sensible data structure and then fill the queue again with the sorted values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.