The implementation process in Java is as follows:
1 Public Static intStrstrChar[] CArray1,Char[] cArray2) {2 if(carray1!=NULL&& carray2!=NULL 3&&!carray1.equals ("") &&!carray2.equals ("")4&& carray1.length>=carray2.length) {5 intM=0;6 for(inti=0;i<=carray1.length-carray2.length;i++){7 if(carray1[i]==Carray2[m]) {8m++;9 if(m==carray2.length) {Ten returnI-carray2.length+1; One } A Continue; -}Else{ -M=0; the } - } - } - return-1; +}
This is a classmate interview C out of a question, require C implementation.
Java implementation issues:
The length property is not allowed. As the development of library functions, these properties are not allowed here.
====
The C language can be manipulated by pointers.
The string in C ends with ' + ' and moves the pointer to see what it refers to.
If CArray2 is empty first, or cArray2 and cArray1 are empty at the same time, it is included; if CArray1 is empty first, it is not included.
=====
To implement a C-pointer-like function in Java, think of:
1, to capture the way the bounds of the anomaly as an array to end the judgment ...
2, add a symbol such as ' # ' to the end, as the end of the flag. But what if the array itself contains: Seemingly no solution.
=========================================
In addition to these, the idea of Java implementation is as follows:
1, traverse cArray1;
2, set the variable m to record the cArray2 position.
The initial value is 0, then the bitwise comparison, and if there are unequal conditions, m resets to 0. CArray1 then traverses backwards, but cArray2 starts from the beginning.
3. Determine the conditions for success. M==carray2.length.
-------
Also, the value of the char type is compared for equality, directly with "= =" because it is the underlying variable ....
Some problems of STRSTR function implemented by Java