Search
 
SCRIPT & CODE EXAMPLE
 

CPP

two pointer in c++

  int i = 0;
 
    // represents second pointer
    int j = N - 1;
 
    while (i < j) {
 
        // If we find a pair
        if (A[i] + A[j] == X)
            return 1;
 
        // If sum of elements at current
        // pointers is less, we move towards
        // higher values by doing i++
        else if (A[i] + A[j] < X)
            i++;
 
        // If sum of elements at current
        // pointers is more, we move towards
        // lower values by doing j--
        else
            j--;
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: number of characters in c++ files 
Cpp :: max of a vector c++ 
Cpp :: do while loop c++ loops continuously 
Cpp :: c++ 2d vector assign value 
Cpp :: mkdir c++ 
Cpp :: terminal compile c++ 
Cpp :: c++ if in equivalent 
Cpp :: C++ string initialization 
Cpp :: cpp Sieve algorithm 
Cpp :: include cpp 
Cpp :: C++ press enter to continue function 
Cpp :: ray sphere intersection equation 
Cpp :: strlen in c++ 
Cpp :: string to int c++ 
Cpp :: c++ iterate over vector of pointers 
Cpp :: Quicksort taking random pivot 
Cpp :: string substr c++ 
Cpp :: pointer address to string 
Cpp :: c++ vector push if not exist 
Cpp :: could not find the task c c++ active file 
Cpp :: c++ thread incide class 
Cpp :: min in c++ 
Cpp :: See Compilation Time in c++ Program 
Cpp :: cpp print variable value 
Cpp :: ++i and i++ 
Cpp :: sum of row s2 d array c++ 
Cpp :: no template named vector in namespace std 
Cpp :: stack c++ 
Cpp :: how to say hello world in c++ 
Cpp :: transformer in nlp 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =