Monday, July 17, 2023

14. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.

 14. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists. 


reverse([],[]).

reverse([X|T],REV):-reverse(T,R),append(R,[X],REV).


OUTPUT:


reverse([1,2,2],X).

X = [2, 2, 1]


No comments:

Post a Comment