You are currently viewing Program to find the reverse of the list in prolog.

Program to find the reverse of the list in prolog.

In previous article we have seen how to append the list into another. In this article, we will see how to reverse a list. To identify a standard technique where we reverse a list by appending its head to the reverse of its tail. The goal succeeds if the result of reversing the order of the elements in list L is List M.

PROGRAM:

reverse([X|Y],Z,W):-REVERSE[Y,[X|Z],W].

reverse([],X,X).

OUTPUT:

Dinesh Kumar Bansal

Dinesh Kumar Bansal is an Indian Software Developer, who is working on ASP.Net, MS-SQL, SAP-ABAP technologies from last one year. His Basic Principle of developing software is, “You have to clear about, what do you want to do, how can it be done”. He always says that development can be done with a cool & fresh mind.

Leave a Reply