Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Java's Deque

Tags:

c#

deque

in Java, there's a class called Deque, and i would like to find something similar to this in .NET (C#).

The reason i need this, is because i need to peek the last item in the collection, and then dequeue the first one in the collection.

Thanks, AJ Ravindiran.

like image 376
TheAJ Avatar asked Oct 25 '25 04:10

TheAJ


1 Answers

Check out .NET's System.Collections.Generic.LinkedList collection, which can be used as a Deque. It's a doubly linked list.

Insertion/Deletion

  • AddFirst: Add to beginning
  • AddLast: Add to end
  • RemoveFirst: Remove from beginning. Does not return value.
  • RemoveLast: Remove from end. Does not return value.

Peeking:

  • First/Last Properties.

    These Return a LinkedListNode<T>, not the actual value. To get the value you have to add .Value to the end.

like image 156
Grzegorz Smulko Avatar answered Oct 26 '25 17:10

Grzegorz Smulko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!