# Data structure C # language version chapter 1st introduction (2)

Source: Internet
Author: User

1.3 mathematical prerequisites

A Set is a whole composed of Some deterministic members (Member) or elements. A member is taken from a larger range and is called a Base Type ). The number of members in a collection is called Cardinality ).

Set features:

1) certainty: Any object can be accurately determined to be an element or not in a set.

2) Interaction: Elements in the set cannot be repeated.

3) No sequence: the element in the set is irrelevant to the sequence.

1.3.4 Recursion

If an algorithm calls itself directly or indirectly, it is called a Recursive algorithm ). Depending on the call method, it can be divided into Direct Recursion and Indirect Recursion ).

Recursive Algorithms are generally not the most effective computer programs to solve the problem. Because recursion includes function calls, the time-space overhead of function calls is required.

Factorial (factorial) function:

C ++ Codes:

[Cpp] // Algri. h
# Ifndef ALGRI_H
# Define ALGRI_H

Int factorial (int n );

# Endif
// Algri. h
# Ifndef ALGRI_H
# Define ALGRI_H

Int factorial (int n );

# Endif [cpp] // Algri. cpp
# Include "Algri. h"
# Include "stdafx. h"

Int factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * factorial (n-1 );
}
// Algri. cpp
# Include "Algri. h"
# Include "stdafx. h"

Int factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * factorial (n-1 );
}
Python Codes:

[Python] "Algri. py"
Def factorial (n ):
If n <= 0:
Return-1;
Elif n = 1:
Return 1;
Else:
Return n * factorial (n-1 );
"Algri. py"
Def factorial (n ):
If n <= 0:
Return-1;
Elif n = 1:
Return 1;
Else:
Return n * factorial (n-1); [python] "Program. py"
From Algri import factorial

Print factorial (10)
"Program. py"
From Algri import factorial

Print factorial (10) C # codes:

[Csharp] class Program
{
Static void Main ()
{
Console. WriteLine (Factorial (10 ));
}

Static int Factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * Factorial (n-1 );
}
}
Class Program
{
Static void Main ()
{
Console. WriteLine (Factorial (10 ));
}

Static int Factorial (int n)
{
If (n <= 0)
Return-1;
Else if (n = 1)
Return 1;
Else
Return n * Factorial (n-1 );
}
}

From. from the perspective of Net, the so-called set can be defined as an object, which provides a structured way to organize arbitrary objects and implements one or more icollections, IDictionary, and System. collections. IList interface. This definition divides the "built-in" set in the System. Collections namespace into three categories:

(1) Ordered Set: a set that only implements the ICollection interface. For example, Stack and Queue.

(2) index set: the set of IList is implemented, and its content is retrieved from digits starting from scratch. For example, ArrayList.

(3) Key set: the set that implements the IDictionary interface. The content of the IDictionary set is usually stored by pressing the key value. For example, Hashtable class.

From xufei96's column

Related Keywords:
Related Article

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.