Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I try to get EXPECTED OUTPUT as with insertInOrder function. Can help? Here is my code: and the output is which is not same with

I try to get EXPECTED OUTPUT as with insertInOrder function. Can help?

Here is my code:

image text in transcribed

and the output is

image text in transcribed

which is not same with expected output.

10 void DoublyList::insertInOrder(int insertNum) 11 { 12 13 Node* newNode = new Node (insertNum, nullptr, last); 14 if (count == 0) 15 { 16 first = newNode; 17 last = first; 18 } 19 else 20 { 21 22 if(insertNum getData()) 23 { 24 newNode->setNext(first); 25 first->setPrev(newNode); 26 first = newNode; 27 } 28 else 29 { 30 Node* current = first; 31 while (current != nullptr) 32 { 33 if (newNode->getData() >= current->getData()) 34 { 35 if (current == last) 36 { 37 last->setNext(current); 38 current ->setPrev(last); 39 last = current; 40 } 41 else 42 { 43 newNode->setPrev(current); 44 newNode->setNext(current->getNext()); 45 current->getNext() ->setPrev(newNode); 46 current->setNext(newNode); 47 48 49 50 } 51 ++count; 52 53 } 54 } */ CS250/ Labs/ $ g++ -C -0 Main.o Main.cpp g++ -C -O Functions.o Functions.cpp g++ -C -0 DoublyList.o DoublyList.cpp g++ Main.o Functions.o Doublylist.o -o Main ./Main TESTING: insertInOrder... Elements inserted (in this order): 8 5 37 53 21 18 73 49 Forward... EXPECTED OUTPUT: 5 8 18 21 37 49 53 73 YOUR OUTPUT: 49 73 18 21 53 37 5 8 Reverse... EXPECTED OUTPUT: 73 53 49 37 21 18 8 5 YOUR OUTPUT: 49 Check first and last nodes... First... EXPECTED OUTPUT: 5 YOUR OUTPUT: 49 Back... EXPECTED OUTPUT: 73 YOUR OUTPUT: 49 Teen

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

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

7. What decisions would you make as the city manager?

Answered: 1 week ago

Question

8. How would you explain your decisions to the city council?

Answered: 1 week ago