简体   繁体   中英

C# and datastructures, do you ever need to write your own?

I'm going through an algorithms book, going through the basic structures like strings, arrays, dictionaries, queues, stacks, and also sorting algorithms etc.

Given C#'s data structures, do you ever need to build out your own structure from scratch, or create your own binary search or whatever or these things are built in for you?

The .NET framework only includes a baseline of common data structures and algorithms, but doesn't cover (nor does it try to cover) everything .

So yes you will definitely have to write your own data structures, tries and priority queues for example come to mind right away. In many cases there are open source projects that cover a wide range of algorithms and data structures so there is no need to reinvent the wheel, but as always more specialized implementations and different optimizations might be needed for individual projects.

As @BrokenGlass says, the.Net framework supplies many baseline data structures. This is your basic toolbox. Open source projects are a great way to learn more about extending and expanding those tools. As such, it is not generally necessary to reinvent the wheel .

To avoid unnecessarily coding your own data structure, it is always a good idea to ask, " is there some library that should suit my requirements: x, y, z? "

That said, I would not discourage you from writing your own data structures as you see a need - in fact, from an academic viewpoint, I encourage it. This experience will give you the knowledge required to:

  1. modify existing data structures to suit your needs
  2. know when existing data structures do not suit your needs

.NET is lacking many common data structures that are in more comprehensive libraries for other languages (such as the C++ standard template library).

I've used both C5 and Wintellect's Power Collections in the past. Of the two, I prefer C5 for collections, but Wintellect for algorithms.

Ah;) Read the book to the end;) There are PLENTY of edge cases that the .NET standard classes do not cover.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM