Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to merge two ordered list generating an ordered list

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

Prolog program to merge two ordered list generating an ordered list.

Code for Prolog program to merge two ordered list generating an ordered list in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    mergelist(l,l,l)
    
clauses
    mergelist([],[],[]).
    
    mergelist([X],[],[X]).
    
    mergelist([],[Y],[Y]).
    
    mergelist([X|List1],[Y|List2],[X|List]) :-
        X <= Y,!,
        mergelist(List1,[Y|List2],List).
        
    mergelist([X|List1],[Y|List2],[Y|List]) :-
        mergelist([X|List1],List2,List).
        
Output :

Goal: mergelist([1,3,5],[2,4,6],List)
List=[1,2,3,4,5,6]
1 Solution

Goal: mergelist([-1,1,4,5],[-3,0,2,3,5],List)
List=[-3,-1,0,1,2,3,4,5,5]
1 Solution
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to merge two ordered list generating an ordered list is from India.
 
View All Articles

Related Articles and Code:


 
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!