Set,stack,queue,dictionary,arraylist,list<t>

Source: Internet
Author: User

Oh, I went, yesterday that the full alignment and search algorithm made my head is big, forget to write Bo, alas, early to fill up ...

There are a lot of things today, but nothing difficult.

Collection: Create and manage groups of related objects the first form of the. Type is: Create a collection of objects.
A collection of flexible processing methods. Unlike arrays, the processing of
The elephant group can dynamically increase and contract depending on the needs of the program changes. For a
Collection, you can assign a "key" to any object that you put in the collection,
So that the key can quickly retrieve the object.
Note: The collection is a class, so you must declare the new collection before you can
To add elements to the. There are two types of collections: generic collections and generic collections.
Make?? Required for generic collection: System.Collections namespace.
Make a generic collection need to be cited?: System.Collections.Generic-named
Space.

Stack:stack are called stacks, stacks, and queues, but the queue is an advanced
The data added and removed from the stack are at the end of the stack.
The data in is LIFO. The Stack class implements the ICollection and
IEnumerable pick? Defined as follows:

New Stack (); Stack<intnew stack<int> ();

Push () interpolates the object? The top of the stack. (? Stack operation)
Pop () Removes and returns the object at the top of the stack. (out of stack operation)
Peek () Returns the object at the top of the stack without removing it.
Contains () determines whether an element is in the stack.
Clear () Removes all objects from the stack.
Count gets the elements contained in the stack.

1. Data structure of last in, first out (LIFO).
2. As you add elements to the Stack, capacity is redistributed on-demand
Increase.
3.Stack accepts NULL as a valid value and allows duplicate elements.

Queue:queue is called a queue, so what is the queue? Data structures with columns
The end of the table, and removed by the other side of the list. It's like a single word.
Can only be entered from the paragraph, from the end of the. The queue class is also implemented
ICollection and IEnumerable?

New Queue (); Queue<stringnew queue<string> ();

Enqueue () Adds the object to the end of the Queue.
Dequeue () Removes and returns the object at the beginning of the Queue.
Peek () Returns the object at the beginning of the Queue but does not remove it.
Clear () Removes all objects from the Queue.
Contains () determines whether an element is in a Queue.
Count gets the number of elements contained in the Queue.

1. First in, Out (FIFO) type data structure.
2. As elements are added to the queue, the capacity is increased by reallocating the on-demand movement. Can you pass the adjustment? TrimToSize to reduce capacity.
3.Stack accepts NULL as a valid value and allows duplicate elements.
4. Queue that is frequently used in AI pathfinding algorithms.

Dictionary:dictionary<tkey, tvalue> class is called Dictionary class, table key and
A collection of values. Which TKey table? The type in the dictionary, the TValue table?
The value type in the dictionary. The dictionary class implements ICollection,
IEnumerable, IDictionary? Defined as follows:

dictionary<stringintnew dictionary<stringint> ();

Add () adds the specified key and value to the dictionary.
TryGetValue () Gets the value associated with the specified key.
Clear () Removes all keys and values from Dictionary<tkey, tvalue>.
Remove () Removes the value of the specified key from Dictionary<tkey, tvalue>.
ContainsKey () Determines whether the Dictionary<tkey, tvalue>, contains the specified key.
Containsvalue () Determines whether Dictionary<tkey, Tvalue> contains a specific value.
Count gets the elements contained in the stack.
Keys gets a collection that contains the keys in the Dictionary<tkey, tvalue>.
Values gets a collection that contains the values in Dictionary<tkey, tvalue>.

1. A dictionary is a generic collection.
2.TKey must be only.
3.Value can be a variable, or it can be an object.

ArrayList: It's a special array. By adding and removing elements, you can
To dynamically change the degree of the array. ArrayList is not a strong type, ArrayList
May not always provide the best performance for a particular task. The ArrayList class implements the
IList, ICollection and IEnumerable? Defined as follows:

New ArrayList ();

Add () Adds the object at the end of the ArrayList.
Insert () inserts an element? The ArrayList at the specified index.
Remove () Removes the first occurrence of a specific object from the ArrayList.
RemoveAt () Removes the element at the specified index of the ArrayList.
Reverse () Reverses the order of the elements in the entire ArrayList.
Contains () determines whether an element is in ArrayList.
Clear () Removes all elements from the ArrayList.
Count gets the elements contained in the stack.

1. How to change the motion? The function.
2. Can be flexible to insert elements, delete elements, access elements.
3. Not strong type, speed and array are slow to get up.

List<t> class: Table? A strongly typed list of objects that can be accessed through an index. Provide?
To search, sort, and manipulate the list. List<t> is ArrayList.
Class, which enables the??? of the generic equivalent class Array implementations that can be dynamically added on demand
ilist<t> generic connection?. The List<t> class also implements the ICollection,
IEnumerable and IList connection? Defined as follows:

list<intnew list<int> ();


Add () Adds the object at the end of the list<t>.
Insert () inserts an element? The list<t> at the specified index.
Remove () Removes the first occurrence of a specific object from the list<t>.
RemoveAt () Removes the first occurrence of a specific object from the list<t>.
RemoveAll () Removes all elements that match the conditions defined by the specified predicate.
Reverse () Reverses the order of the elements in the entire list<t>.
IndexOf (T) searches for the specified object and returns the first occurrence of the entire list<t>
The zero-based index of the Sort (). The default is to sort the elements in the entire list<t>.
Contains () determines whether an element is in ArrayList.
Clear () Removes all elements from the list<t>.
Count gets the elements contained in the stack.

1. In ArrayList phase, list<t> is good and type safe.
2. If the type T of the List<t> class is exactly the same. However, if you want to consider implementation and boxing issues.

  //randomly generates an ordered N point (represented by a struct) on a finite planar area (1000 * 1000) and saves it in the collection .//(1) Output The coordinate information of all points//(2) Calculate the sum of the ordered adjacent two points distance (first sort, then distance)Random Rd=NewRandom ();            Point P; Dictionary<int,int> Position =Newdictionary<int,int>(); intn =int.            Parse (Console.ReadLine ()); inti =0;  for(intj =0; J < N; J + +) {p.x= Rd. Next (0, +); P.Y= Rd. Next (0, +); intpos =10000* p.x +p.y; Position.                ADD (i, POS); I++; }            //Output Dictionary            foreach(keyvaluepair<int,int> Iteminchposition) {                intx = Item. Value/10000; inty = Item. Value%10000; Console.WriteLine ("({0},{1})", x, y);            } Console.WriteLine (); //sort of dictionary bubbles             for(intj =0; J < I; J + +)            {                 for(intm =0; M < i-j-1; m++)                {                    if(Position[m] > position[m +1])                    {                        inttemp =Position[m]; POSITION[M]= Position[m +1]; Position[m+1] =temp; }                }            }            foreach(keyvaluepair<int,int> Iteminchposition) {                intx = Item. Value/10000; inty = Item. Value%10000; Console.WriteLine ("({0},{1})", x, y);            } Console.WriteLine (); //ask for distance = =            Doublesum =0;  for(intj =0; J < i-1; J + +)            {                intX1 = Position[j]/10000; inty1 = position[j]%10000; intx2 = position[j +1] /10000; inty2 = position[j +1] %10000; inttemp = (x2-x1) * (x2-x1) + (y2-y1) * (Y2-y1); Sum+=System.Math.Sqrt (temp); } Console.WriteLine (sum);

Set,stack,queue,dictionary,arraylist,list<t>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.