The O (1) algorithm of the sword means the node to which the pointer points

Source: Internet
Author: User

Topic

1. Remove the node that you want to delete ptobedeleted the node that is behind node ptobedeleted

2. Consider what to do if the deleted node is the last node

3. Consider what to do if there is only one node in total and the deletion is the head node or the tail.

——————————————————————————————————— the use of function pointers, a special case that moves all the odd numbers to the front of all even numbers —————————————————————————————————————————————— ————————

Is the same as the idea of fast sorting, that is, when the function is called the form of a function pointer, for the beginning of the function pointer is not familiar, now the function pointer to a learning or review process.

For some vague concepts to organize:

What is the difference between a pointer function and a function pointer first:

(1) Pointer function refers to a function with a pointer, that is, the essence is a function. A function return type is a pointer to a type

The form of the definition is: type identifier * Function name (parameter table )

First it is a function, except that the return value of this function is an address value. The function return value must be accepted with a pointer variable of the same type, that is, the pointer function must have a function return value, and in the keynote function, the function return value must be assigned to a pointer variable of the same type.

Said:

float *fun ();

float *p;

p = Fun (a);

(2) Note that the pointer function is different from the function pointer representation method, do not confuse. The simplest way to discern is to see if the pointer in front of the function name is enclosed in parentheses (), and if it is included as a function pointer, the inverse is a pointer function

A function pointer is a pointer variable to a function, which is essentially a pointer variable.

 Int (*f) (int x); /* Declare a function pointer * /

 F=func; /* assigns the first address of the Func function to the pointer f * /

Type descriptor (* Function name ) (parameter )

In fact, this is not called the function name, it should be called the pointer variable name.

(3) pointer to pointer

form of declaration: char * * CP;

So there will be an explanation as follows

The pointer's pointer needs to use the pointer's address.
Char c= ' A ';
Char *p=&c;
Char **cp=&p;
A pointer to a pointer can access not only the pointer it points to, but also the data it points to. Here are a few examples:
Char *P1=*CP;
Char C1=**CP;

The key is to master the precedence of operators and how to use + +
*p=*p+1; here * for indirect access, p points to address content +1 after the value assigned to the address that P points to
*p++;//here * and + + are the same priority, p first and + + are combined; Move right p++ is first use p, after P value +1
The difference between *p++ and *p=*p+1 is that the latter is the value +1 of the address that P points to, the former is the address +1 of P, and all the latter, that is, the individual *p++, which is equivalent to p++, is an easy-to-misunderstand notation that does not use *p++ in the actual program;
*++p;//is similar, first p points to a unit, and then indirectly accesses the value of the address to which P points, and also does not use *++p alone; statement, if *++p is used alone, and ++p equivalent

(4) Pointer to pointer array
Pointer to a pointer to another usage array of old processing pointers. Some programmers prefer to use pointer arrays instead of multidimensional arrays, and a common use is to manipulate strings

One example of this is the use of:
Char *names[]=
{
Bill,
Sam,
Jim,
Paul,
Charles,
0
};

Main ()
{
Char **nm=names;
while (*nm!=0) printf (%s\n,*nm++);
}

Note that the last element in the array is initialized to0, whileloop to determine whether the end of the array is at the same time. Pointers with a value of 0 are often used as terminators for loop arrays. The programmer calls the 0-value pointer a null pointer (NULL). Using a null pointer as the terminator, when the tree species additions and deletions, it is not necessary to change the code traversing the array, because the array still ends with a null pointer.



The O (1) algorithm of the sword means the node to which the pointer points

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.