(str1, str2)
| 1 | def 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 | |
| 19 | print(strcmp("123", "123")) |
| 20 | print(strcmp("123", "124")) |