Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

ProLog Program to sort the list of integers using Insertion Sort

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

Program to sort the list of integers using Insertion Sort.

Code for ProLog Program to sort the list of integers using Insertion Sort in Artificial Intelligence

trace
Domains
    list = integer*.
    element = integer.
    
Predicates
    insertSort(list, list).
    insertItem(element, list, list).    
    printlist(list).
    
Clauses
    insertSort([H|List], Result) :-
        insertSort(List, Temp), 
        printlist(Temp),    
        insertItem(H, Temp, Result).
                
    insertSort([], []).        
    
    insertItem(X, [H|List], [H|Result]) :-
        H < X, !, 
        insertItem(X, List, Result).
    insertItem(X, List, [X|List]).    
        

    printlist([]) :- nl.
    printlist([X|List]) :-
        write(X, " "),
        printlist(List).
        
        
  
Share: 



Milind Mishra
Milind Mishra author of ProLog Program to sort the list of integers using Insertion Sort 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!