Data structure in C #: C # basis

First, the array (Array)

Array has the following features:

  1. Linear array belong structure in memory is stored in a row.
  2. It must be the same type of array elements.
  3. Arrays can be accessed directly through the index.
  4. Find an array of very fast speed, add and delete slow.
  5. Array during initialization to specify the length of the array.

Second, the dynamic array (the ArrayList)

Dynamic array has the following characteristics:

  1. Underlying ArrayList is actually an array.
  2. ArrayList statements necessary to specify the length of time, according to an increase would reduce the length of the data stored or dynamically.
  3. ArrayList will all elements as Object processing, it is possible to store different types of data elements.
  4. When you insert and delete an element, it will move the location of all the elements after it inefficient, frequently insert or delete elements recommended LinkedList.
  5. ArrayList is non-type-safe, when inserting and removing elements will be unpacking and packing problems affecting performance and low efficiency.

Third, the generic List

Generic List has the following characteristics:

  1. List ArrayList is a generic class.
  2. Generic List need to specify a particular type when declared.
  3. List no generic boxing and unboxing operation, so List than ArrayList efficient and safe type.

Fourth, the doubly linked list (LinkedList)

Doubly linked list has the following characteristics:

  1. List of nodes in memory space is not continuous, each space called a node, each node there precursor and a rear pointer, each pointing to a previous node and the node, and thus added to the list remove elements of high effect, only need to change the pointer to point to the appropriate nodes.
  2. Find a list of low efficiency. You can not be accessed through the index to find the time element, can only start from scratch in order to find the address.

V. stack (Stack)

Stack has the following characteristics:

  1. Stack is a last-out principle, the first element inserted last accessed, the last element inserted the first to be visited.
  2. Push the stack, Pop the stack and return the top element, Peek returns only the top element.

Six, Queue (list)

The list has the following characteristics:

  1. The list is the FIFO principle, where the first element of the first to be visited, and finally into the last element is accessed.
  2. Queues Enqueue, Dequeue the queue and returns the first element of the column, Peek column only return the first element. 

Seven Dictionary (Dictionary)

Dictionary has the following characteristics:

  1. You need to specify the key and value data types when creating a dictionary.
  2. key value in the dictionary is unique, value value may not be unique.
  3. You can quickly find the key by a corresponding value, fast speed, but consumes memory.

Second, the data structures of several common usage scenarios

Array Determine the number of elements need to be addressed and need to be accessed using the subscript considered, but is recommended to use List <T>.
ArrayList Not recommended, it is recommended to use the generic List <T>.
Generic List <T> The number of elements need to be addressed when uncertainty is usually recommended.
LiskedList<T> List for the number of elements is not fixed, if necessary and frequent changes in node list element changes in high efficiency.
Queue<T> FIFO queue appropriate for the situation.
Stack<T> Stack the case for the after advanced.
Dictionary<K,T> Dictionary for applications that require the operation of key situations.

 

Guess you like

Origin www.cnblogs.com/dotnet261010/p/12333598.html