MCPcopy
hub / github.com/itcharge/AlgoNote / strcmp

Function strcmp

codes/python/04_string/string_Strcmp.py:1–17  ·  view source on GitHub ↗
(str1, str2)

Source from the content-addressed store, hash-verified

1def strcmp(str1, str2):
2 index1, index2 = 0, 0
3 while index1 < len(str1) and index2 < len(str2):
4 if ord(str1[index1]) == ord(str2[index2]):
5 index1 += 1
6 index2 += 1
7 elif ord(str1[index1]) < ord(str2[index2]):
8 return -1
9 else:
10 return 1
11
12 if len(str1) < len(str2):
13 return -1
14 elif len(str1) > len(str2):
15 return 1
16 else:
17 return 0
18
19print(strcmp("123", "123"))
20print(strcmp("123", "124"))

Callers 1

string_Strcmp.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected