Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started