MCPcopy Create free account
hub / github.com/Berkeley-CS61B/skeleton-sp23 / nextString

Method nextString

lab08/tests/speed/StringUtils.java:45–53  ·  view source on GitHub ↗

Returns the string that comes right after S in alphabetical order. For example, if s is 'potato', this method will return 'potatp'. If the last character is a z, then we add to the next position, and so on.

(String s)

Source from the content-addressed store, hash-verified

43 * on.
44 */
45 public static String nextString(String s) {
46 /* Handle all zs as a special case to keep helper method simple. */
47 if (isAllzs(s)) {
48 return allAs(s.length() + 1);
49 }
50 char[] charVersion = s.toCharArray();
51 incrementCharArray(charVersion, charVersion.length - 1);
52 return new String(charVersion);
53 }
54
55 /**
56 * Helper function for nextString. Increments the Pth position of X

Callers 1

insertInOrderMethod · 0.95

Calls 3

isAllzsMethod · 0.95
allAsMethod · 0.95
incrementCharArrayMethod · 0.95

Tested by

no test coverage detected