当前位置:网站首页>Double pointer Foundation

Double pointer Foundation

2022-07-05 05:16:00 lee2813

One 、 Double pointer

Double pointers are mainly used to traverse arrays , Two pointers point to different elements , Work together , Generally speaking, they are all in the same array .

Two 、 classification

According to the different problems , The direction of movement of the pointer will also be different , It can be divided into two situations :

  • Traversal direction is the same and will not intersect
    This kind of situation is generally used to solve the problem of searching a certain interval of the array , Also known as the sliding window problem .
  • The traversal direction is opposite and the array itself is orderly
    This situation is generally used for element search

Applications can be divided into :

  1. Two number sum problem
  2. Merge two ordered arrays
  3. Speed pointer problem
  4. Sliding window problem

 Insert picture description here

3、 ... and 、 A basic review of pointers

  • const Heel int, Value cannot be changed , Pointer can be changed
const int * p2 = &x  
  • const Followed by a pointer p3 front , Value can be changed , The pointer cannot be changed
int * const p3 = &x
  • const Heel int And a pointer p4, Value can be changed , The pointer cannot be changed
const int  * const  p4 = &x 
  • * Left Union , Therefore, it is a function whose return type is pointer
int * function(){
    }
  • ( ) hold * Included , And function combination , Therefore, it is return ; Pointer of type function
int func2(int a,int b){
    }
int (*function)(int,int) = func2;

 Insert picture description here

原网站

版权声明
本文为[lee2813]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140623115916.html