6.10 Lab*: Singly-Linked Lists (Park)
Optimize searchList
This commit is contained in:
parent
4ae56c5a42
commit
5b5e2b6d67
6
01-stacks/.idea/vcs.xml
generated
Normal file
6
01-stacks/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -118,12 +118,13 @@ bool LinkedList::searchList(string target, Park &dataOut) const {
|
|||||||
pCur = head->next;
|
pCur = head->next;
|
||||||
|
|
||||||
// While pCur points to a node, traverse the list.
|
// While pCur points to a node, traverse the list.
|
||||||
while (pCur && pCur->park.getCode() != target) {
|
// Since the list is sorted, we can stop when the target is less than the current node.
|
||||||
|
while (pCur && pCur->park.getCode() < target) {
|
||||||
pCur = pCur->next;
|
pCur = pCur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the target was found, copy the data
|
// If the target was found, copy the data
|
||||||
if (pCur) {
|
if (pCur && pCur->park.getCode() == target) {
|
||||||
dataOut = pCur->park;
|
dataOut = pCur->park;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user