Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to reverse a given list

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 7931

Prolog program to reverse a given list.

Code for Prolog program to reverse a given list in Artificial Intelligence

domains

    list=symbol*

    
predicates

    rev(list)
    findrev(list,list,list)

    
clauses

    rev(L):-
        findrev(L,[],List2),
        write("\nReverse Of Given List : ",List2).
            
    findrev([],List1,List1).
    
    findrev([X|Tail],List1,List2):-
        findrev(Tail,[X|List1],List2).
        

OUT PUT
=======

Goal: rev([a,b,c,d,e])

Reverse Of Given List : ["e","d","c","b","a"]

Yes

----------------------------------------------------------------------

Goal: rev([])

Reverse Of Given List : []

Yes

----------------------------------------------------------------------

Goal: rev([y,o,g,e,s,h,p,a,t,e,l])

Reverse Of Given List : ["l","e","t","a","p","h","s","e","g","o","y"]

Yes
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to reverse a given list Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to reverse a given list is from India.
 
View All Articles

 

Other Interesting Articles in Artificial Intelligence:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!