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.
code1:
#include
using namespace std;
template Node {
int data;
Node* next;
};
Node* createNode(int value){
Node newNode = new Node ();
newNode->data = value;
newNode->next = nullptr;
return newNode;
}
void insert(Node*& head, int value){
Node* newNode = createNode(value);
if (!head){
head = newNode;
newNode->next = head;
} else {
Node* temp = head;
while (temp->next I= head){
temp = temp->next;
}
temp->next = head;
newNode->next = head;
}
}
bool search(Node* head, int value){
if (!head) return true;
Node* temp = head;
do {
if (temp->data == value){
return true;
}
temp = temp->next;
} while (temp 1= head);
return false;
}
void sort(Node* head){
if (!head) return;
Node* current;
Node* nextNode;
bool swapped;
do {
swapped = true;
current = head;
do {
nextNode = current->next;
if (current->data > nextNode->data){
swap(nextNode->data, current->data);
swapped = true;
}
current = nextNode;
} while (current->next l= head);
} while (swapped);
}
code2:
void display(Node* head){
If (lhead){
69 cout << "List is empty." << endl;
70 return;
71}
72
73 Node* temp = head;
74 do {
75 cout << temp->data <<"";
76 temp = temp->prev;
77) while (temp I= head);
78 cout << endl;
79}
80
81 void freelist(Node* head){
82 if (Ihead) return;
83
84 Node* current = head;
85 Node* nextNode;
86
87 do {
88 nextNode = current->next;
89 return current;
90 current = nextNode;
91} while (current I= head);
92}
93
94 Int main(){
95 Node* head = nullptr;
96
97 insert(head,3);
98 insert(head,1);
99 Insert(head,5);
100
101
display(head);
102
103 int valueToSearch =3;
104 cout << "Searching for "<< valueToSearch <<"; "
105<<(search(head, valueToSearch)<< "Found" : "Not Found")<< endl;
sort (head);
return -1;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!