Below there are 4 different ways of computing list reversal. One method does not work, why not? Comment each line of the reverse functions. Where does the reversa

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question

Computer Science

Below there are 4 different ways of computing list reversal. One method does not work, why not? Comment each line of the reverse functions.

Where does the reversal take place clearly indicate in your comments.

 

#define reverse_method 3

 

#if reverse_method == 1

void DLinkedList::reverse()

{

DLinkedList temp;

while (!empty())

{

Elem s = front();

removeFront();

temp.addFront(s);

}

swap(*this, temp);

}

#elif reverse_method == 2

void DLinkedList::reverse()

{

DLinkedList temp;

while (!empty())

{

Elem s = front();

removeFront();

temp.addBack(s);

}

while (!temp.empty())

{

Elem s = temp.front();

temp.removeFront();

addFront(s);

}

}

#elif reverse_method == 3

void DLinkedList::reverse()

{

DLinkedList* temp = new DLinkedList;

while (!empty())

{

Elem s = front();

removeFront();

temp->addFront(s);

}

swap(*this, *temp);

}

#elif reverse_method == 4

void DLinkedList::reverse()

{

DLinkedList temp;

 

while (!empty())

{

Elem s = front();

removeFront();

temp.addFront(s);

}

 

while (!temp.empty())

{

Elem s = temp.front();

temp.removeFront();

addBack(s);

}

}

#endif

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT