Data Structure 1

Source: Internet
Author: User

Reading Haobin-Data Structure notes

/*


*/
Data Structure
1. data structure definition
2. Prerequisites
3. Module 1: linear structure (array and linked list, two common applications: queue and stack)
4. Special Topics: recursion (conversion of recursion and loop, factorial, Tower of arms, and maze)
5. Module 2: Non-linear structures (trees and graphs)
6. Module 3: Search and sorting (half, and the five most common sorting methods)

Data structure:
What is data structure?
Convert the actual problem to a specific data type, and use a storage structure to organize such a large amount of data to be stored in the memory, and writeProgramIt is called the data structure.
To implement a functionCodeWe becomeAlgorithm

Measure the algorithm standard:
1. time complexity-Approximate number of program executions
2. space complexity-approximately the maximum memory occupied
3. Difficulty of Algorithms
4. Robustness-illegal Input

 

 

Well, the above is to make it easy for everyone. Let's talk about the data structure preparations.
We have learned the C language before. In fact, the preparatory knowledge of this data structure is to review the C language.

Good. Let's review the C language.
I. pointer
2. struct
3. Dynamic Memory Allocation

Pointer
/*
Pointer of basic type
*/
# Include <stdio. h>
Int main ()
{
Int I;
Int * j = & I; // defines the address where the variable J points to I for an int * type (called an int type pointer ).
I = 5;
Printf ("% d", * j );
Return 0;
}

 

# Include <stdio. h>
Void F (int I)
{
I = 100;
}

Int main (void)
{
Int I = 9;
F (I );

Printf ("% d", I );
Return 0;

}

// The I of the f function and the I of the main function are pushed in by a stack, so there is no pressure, so they cannot access each other.
Address Concept

# Include <stdio. h>
Void F (int * I) // defines a form parameter. Change the name of the form parameter to I, type: int *
{
I = 100;
}

Int main (void)
{
Int I = 9;
F (& I); // send this I address to another

Printf ("% d", I );
Return 0;

}

 

The CPU can only access the memory. Therefore, you must first import the hard disk into the memory.
Access Memory through address bus, control lines, and data lines
The address line is used to determine the unit.
Whether the control line is read or write
The data line interacts with the CPU.

The address is the number of the memory unit.
Non-negative integer starting from 0
Value Range: 0-ffffffff [0-4g-1]

Pointer:
Pointer is the address
The pointer variable is the variable that stores the address.
The essence of a pointer is a non-negative integer with limited operation. // The operation is restricted: the pointer can only be subtracted under certain circumstances.

/*
Relationship between pointers and one-dimensional arrays
*/

# Include <stdio. h>
 
Int main (void)
{
Int A [5] = {1, 2, 3, 4, 5 };
// One-dimensional array name a stores the address of the first element of the array
// A is a pointer constant! Generally, constants are assigned values at the beginning and cannot be changed.


A [1] = * (a + 1)
A [3] = * (3 +)
A is the first, 3 is the third, * is itself

The value of P + I is the number of P + I * bytes.




Return 0;

}

# Include <stdio. h>

// Two parameters are required. The first element is the first address, and the second is the number of array elements.
// Void array (int A [], int N)
Void array (int * P, int N)
{
* (3 + p) =-1;

}

Int main (void)
{
Int A [5] = {1, 2, 3, 4, 5 };
Array (A, 5 );

Printf ("% d", a [3]);
Return 0;
}

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.