Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

max in a list

Status
Not open for further replies.

gaurav12316

Programmer
Apr 18, 2009
1
US
I want to write a procedure max_nested_list/2 to find a maximum from a nested list.

For Example...

?- max_nested_list([], Z).

Z = []
?- max_nested_list([2, a], Z).

Z = 2 ;

No
?- max_nested_list([[1, a, f(b)], [[[5.2, a], 2], 4.3], [3, h(a)]], Z).

Z = 5.2 ;

No
 
You must test if the current element of the list is a list.
If it is, you must
- find the max of this list (e.g. call max_nested_list with this list)
- compare with the current max
- continue with the next element of the first list.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top