Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C# Data Structures and Algorithms

You're reading from  C# Data Structures and Algorithms

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788833738
Pages 292 pages
Edition 1st Edition
Languages
Author (1):
Marcin Jamro Marcin Jamro
Profile icon Marcin Jamro
Toc

Linked lists


While using the List generic class, you can easily get access to particular elements of the collection using indices. However, when you get a single element, how can you move to the next element of the collection? Is it possible? To do so, you may consider the IndexOf method to get an index of the element. Unfortunately, it returns an index of the first occurrence of a given value in the collection, so it will not always work as expected in this scenario.

It would be great to have some kind of pointer to the next element, as shown in the following diagram:

With this approach, you can easily navigate from one element to the next one using the Next property. Such a structure is named the single-linked list. However, can it be further expanded by adding the Previous property to allow navigating in forward and backward directions? Of course! Such a data structure is named the double-linked list and is presented in the following diagram:

As you can see, the double-linked list contains...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime