Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using the Data Structure of LinkedList. Can you help me fixing this methods? When I put a sentence like: hello world this is

I am using the Data Structure of LinkedList. Can you help me fixing this methods? When I put a sentence like: hello world this is the output-> Pig latin: hello world
Pig Latin: oworlday. It is supposed to be ellohay orldway. C++ I will give like. template
void LinkedList::moveToEnd(Node*& NewPtr)
{
if (NewPtr == nullptr || NewPtr->getNext()== nullptr)
{
return;
}
Node* temp = NewPtr;
NewPtr = NewPtr->getNext();
while (temp->getNext()!= nullptr)
{
temp = temp->getNext();
}
temp->setNext(NewPtr);
NewPtr = NewPtr->getNext();
temp->setNext(nullptr);
}
template
void LinkedList::addChar(Node*& newPtr){
Node* temp = newPtr;
while (temp->getNext()!= nullptr){
temp = temp->getNext();
}
temp->setNext(new Node('a')); // Fix the method call
temp = temp->getNext();
temp->setNext(new Node('y')); // Fix the method call
}
template
string LinkedList::pigLatin(const string& cadena){
Node* newPtr = nullptr;
Node* curPtr = nullptr;
for (char letra : cadena){
if (letra !=''){
if (newPtr == nullptr){
newPtr = new Node(letra);
curPtr = newPtr;
}
else {
curPtr->setNext(new Node(letra));
curPtr = curPtr->getNext();
}
}
else {
moveToEnd(newPtr);
addChar(newPtr);
}
}
moveToEnd(newPtr);
addChar(newPtr);
string result = "Pig Latin: ";
curPtr = newPtr;
while (curPtr != nullptr){
result += curPtr->getItem();
curPtr = curPtr->getNext();
}
cout << result << endl;
return result;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions