c# - Is there a better way to implement a Remove method for a Queue? -


First of all, just grant that I actually include queue < T & gt; want functionality> - FIFO, generally only requires nQ / DQ , etc. - and so I "really want" / P>

For example, I have a queue "(I know about RemoveAt . DatapoProcus at the data points that need to be processed in that order in which they come from time to time, There will be some code by the way:

  while (dataToProcess.Count> 0) {DataPoint Point To Procrocess = dataToProcess.Dequeue (); ProcessDataPoint (pointToProcess);}  

But then, for whatever reason, it has come to know that a special data point added in the Q should be processed not If this is the same method for this:

  dataToProcess.Remove (badPoint);  

I understand that there is not really any way in which anybody < Code> Remove method that does not include the sum of some form; However, a Qi and lieutenant; T> actually does not allow you to just walk and remove some items randomly The only solution I could understand was:

  remove the boole (t item) {bull stuff you = wrong; // To set up a permanent line, one of the items is one / one line & lt; T & gt; Receive Q = new queue & lt; T & gt; (); // Transfer all non-matching items to the temporary queue while (this account> gt; 0) {T Next = this.Dequeue (); If (next. Aquals (item)) {itemFound = true; } And {recieved. Enque (next); }} // Returning back to the original // queue (received QTY;) {this.Enqueue (receive queue.Dequeue ()); } Items for return; }  

Is this ridiculous? It definitely looks looks , but I can not really see a better way than writing a custom class. And yet, the best way I can implement the remove method is by applying a LinkedList & lt; T & gt; could used to think internally.

I think switching to a new custom class, which is linked to the internally, only a few minutes And you will be more demonstrative than what you have.

  Public category special questions & lt; T & gt; {Linkedlist & lt; T & gt; List = new linked list & lt; T & gt; (); Public Zero Enqueue (TT) {list.AddLast (t); } Public Tea Dequ () {var results = list.first.view; List.RemoveFirst (); Return result; } Public T Peak () {Return List. First. value; } Remove Public Hair (TT) {Return List. Remove (T); } Public int count {get {return list.Count; }}}  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -