Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Help me... please :

delete median node(s) in queue
Posted
Updated 9-May-12 21:19pm
v2
Comments
OriginalGriff 10-May-12 3:22am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Stefan_Lang 11-May-12 9:58am    
Try writing a program. You are the one supposed to learn this, not us. If you don't ever try, you will never be able to program on your own. Solution 1 already outlined the path for you.

If you run into an obstacle or don't understand something specific, you are welcome to ask, and we will try to help you understand and fix the problem.

1 solution

Hi i hav an idea but didnt try will it work r not.
1.Collect the values in array from queue.
2.Sort them using any sort.
3.Find the middle value.
4.int NoToRemove = middlevalue.
5.queue.Remove(NoToRemove).
C#
class Program
{
    static void Main()
    {
    // New Queue of integers.
    Queue<int> queue = new Queue<int>();
    queue.Enqueue(5);
    queue.Enqueue(10);
    queue.Enqueue(15);
    queue.Enqueue(20);

    // Create new array with Length equal to Queue's element count.
    int[] array = new int[queue.Count];

    // Copy the Queue to the int array.
    queue.CopyTo(array, 0);

   //sort the array and find the middle value

   int textToRemove = middlevalue;
   queue.Remove(texttoRemove); 

   }
}

i think this will work....
 
Share this answer
 
v2
Comments
Argonia 10-May-12 4:34am    
if i am not wrong al-sawsana wants c++ code ,this is c#. The idea is the same but you have to use stl ,or make the sort function and the struct for the Queue and it has to be linked list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900