Question: Please modify the code as follows. 1 . Add a function named findMin which finds the minimum value in the list. Thereafter, the main function
Please modify the code as follows.
Add a function named "findMin" which finds the minimum value in the list. Thereafter, the "main" function should print the value returned from the "findMin" function.
Add a function named "findMax" which finds the maximum value in the list. Thereafter, the "main" function should print the value returned from the "findMax" function.
Modify the main function to call "findMin" and "findMax".
#include
using namespace std;
struct Node
int data;
struct Node
next;
;
struct Node
head
NULL;
void printList
Node
curr
head;
while
curr
NULL
cout
curr
data
;
curr
curr
next;
cout
endl;
void insertFirst
int data
Node
newNode
new Node;
newNode
data
data;
newNode
next
NULL;
if
head
NULL
head
newNode;
else
newNode
next
head;
head
newNode;
void insertLast
int data
Node
newNode
new Node;
newNode
data
data;
newNode
next
NULL;
if
head
NULL
head
newNode;
else
Node
curr
head;
while
curr
next
NULL
curr
curr
next;
curr
next
newNode;
void insertAtPos
int data, int pos
Node
newNode
new Node;
newNode
data
data;
newNode
next
NULL;
int curPos
;
if
head
NULL
head
newNode;
else
Node
curr
head;
Node
prev;
while
curPos
pos && curr
next
NULL
prev
curr;
curr
curr
next;
curPos
;
prev
next
newNode;
newNode
next
curr;
void deleteAtPos
int pos
Node
curr
head;
int curPos
;
if
head
NULL
if
pos
head
curr
next;
delete curr;
else
Node
prev;
while
curPos
pos && curr
next
NULL
prev
curr;
curr
curr
next;
curPos
;
prev
next
curr
next;
delete curr;
int search
int value
int pos
;
Node
curr
head;
while
curr
NULL
if
curr
data
value
return pos;
pos
;
curr
curr
next;
return
;
int main
cout
Hello World!
;
insertFirst
;
insertFirst
;
insertFirst
;
insertFirst
;
printList
;
insertLast
;
insertLast
;
insertAtPos
;
printList
;
deleteAtPos
;
printList
;
deleteAtPos
;
printList
;
cout
search
;
int pos
search
;
cout
pos;
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
