Hi having trouble with this homework assignment and hopefully a fresh pair of eyes can see where I went wrong in this assignment. So the assignment is that given a string to store it in a linked list and give all possible substrings that start with A and end with B.
For Example:
Enter a string: CABAAXBYA
Substring 1: AB
Substring 2: ABAAXB
Substring 3: AAXB
Substring 4: AXB
Total 4 substrings
int LinkedList::substring() const
{
int counter = 0;
Node* p = first;
Node* begin = nullptr;
Node* end = nullptr;
do
{
// find starting A
while (p && p->data != 'A')
p = p->next;
begin = p;
// find ending B
while (p && p->data != 'B')
p = p->next;
end = p;
if (begin && end)
++counter;
}
while (begin && end);
return counter;
}
@kbw
That code does not work for what I need to do, it is suppose to display each substring you're just counting how many substrings there are and yes each node holds just one character of the string.