Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Find max value in linked list

Suppose Given Linked list contain following nodes data [7 ,8 ,6 ,9, 3, 11, 8, 10 ].Our goal is to Find max value in linked list.

View insertion process.

Try it yourself


in this linked list largest element is [11].

root_ptr 1081139687

Algorithm: Finding big node value.

Hint: Use one integer variable max_value and assign it first node value of linked list. temp are linked list pointer there are pointed of a first node of linked list . In this while loop, compare if(temp->data>max_value) then change max_value to temp->data value. and temp pointer are move to next node. continue this process. until temp are not NULL. if temp are NULL that means end of this process. and we are getting big node value.

C program to find largest node value.


Code execution: view code execution process.

Stack Areamainroot(pointer)find_maxmax_value (int) =9temp(pointer) Heap Areastruct Nodedata (int)= 7next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 6next (pointer) struct Nodedata (int)= 9next (pointer) struct Nodedata (int)= 3next (pointer) struct Nodedata (int)= 11next (pointer) struct Nodedata (int)= 8next (pointer) struct Nodedata (int)= 10next (pointer)= NULL

Note that not given all step of execution process here. view more.

Try it yourself

Spread the post

Recommended Posts: