+ 1
max and min value of random number generated linked list in C++
i need to find the min and max value if a singly linked list with random # generator
4 ответов
+ 8
Mikayla Chandler ,
before we are going to help you, please present your attempt here. if you haven't done a try by yourself so far, please do so. create your code in playground and post the link to it here.
please also provide a proper task description with sample of input and output.
thanks!
+ 3
Mikayla Chandler
Assuming your list has been generated and you only need to find min & max, you could do the following.
Let's call your list/array -> arr
Create 2 variables -> min, max and assign them a value of arr[0], which is equal to the first item in the list
You could then create a loop which inspects each item in the list.
If the item is smaller than min, re-assign the value of min to the new item.
Do the same with max if the item is larger than the value of max
When you finish the loop, min will contain the smallest number & max will contain the largest number
print out your 2 values
+ 1
Mikayla Chandler
Thanks 😁👍& well done!
+ 1
thank you all for your help i will post the code since i made an A on the project