![]() |
VOOZH | about |
As we are given two paths of two files, we have to compare these two paths and check whether they are equal or greater or smaller using a C++ program.
Input:
path1 = "/a/b/c" , path2 = "/a/b/"
Output:
path1 is greater than path2
Example:
/a/b/c is greater than /a/b/ /a/b is equal to /a/b /a/b is less than /a/b.
while(path1[i] != '\0' || path2[i] != '\0'){
//compare the character
//increment value of i
}
OR
for(int i = 0; path1[i] != '\0' || path2[i] != '\0'; i++){
//compare the character
}
Below is the implementation of the above approach:
/a/b/c is not equal to /a/b/ /a/b is equal to /a/b /a/b is not equal to /a/b.
if(path1 > path2) // path1 is greater else if(path1 < path2) // path2 is greater else // both paths are same
Example:
/a/b/c is greater than /a/b/ /a/b is equal to /a/b /a/b is less than /a/b.
Time Complexity: O(1)
Auxiliary Space: O(1)