Question: Study the code which contains errors in the two images below. Provide the line number in which the error occurs and the corrected code. code
Study the code which contains errors in the two images below. Provide the line number in which the error occurs and the corrected code.
code:
#include
using namespace std;
template Node
int data;
Node next;
;
Node createNodeint value
Node newNode new Node ;
newNodedata value;
newNodenext nullptr;
return newNode;
void insertNode& head, int value
Node newNode createNodevalue;
if head
head newNode;
newNodenext head;
else
Node temp head;
while tempnext I head
temp tempnext;
tempnext head;
newNodenext head;
bool searchNode head, int value
if head return true;
Node temp head;
do
if tempdata value
return true;
temp tempnext;
while temp head;
return false;
void sortNode head
if head return;
Node current;
Node nextNode;
bool swapped;
do
swapped true;
current head;
do
nextNode currentnext;
if currentdata nextNodedata
swapnextNodedata, currentdata;
swapped true;
current nextNode;
while currentnext l head;
while swapped;
code:
void displayNode head
If lhead
cout "List is empty." endl;
return;
Node temp head;
do
cout tempdata ;
temp tempprev;
while temp I head;
cout endl;
void freelistNode head
if Ihead return;
Node current head;
Node nextNode;
do
nextNode currentnext;
return current;
current nextNode;
while current I head;
Int main
Node head nullptr;
inserthead;
inserthead;
Inserthead;
displayhead;
int valueToSearch ;
cout "Searching for valueToSearch ;
searchhead valueToSearch "Found" : "Not Found" endl;
sort head;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
