Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to insert an element anywhere in the list

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

Prolog program to insert an element anywhere in the list.

Code for Prolog program to insert an element anywhere in the list in Artificial Intelligence

domains
    x = integer
    l = integer*
    
predicates
    insert(x,l,l)
    delete(x,l,l)
    concatenate(l,l,l)
    
clauses
    concatenate([],L,L).

    concatenate([X|L1],L2,[X|L3]) :-
        concatenate(L1,L2,L3).
    
    delete(X,L,L1) :-
        concatenate(L3,[X|L2],L),
        concatenate(L3,L2,L1).

    insert(X,[],[X]).
            
    insert(X,L,L1) :-
        delete(X,L1,L).
  
Share: 


Didn't find what you were looking for? Find more on Prolog program to insert an element anywhere in the list Or get search suggestion and latest updates.

Milind Mishra
Milind Mishra author of Prolog program to insert an element anywhere in the list is from India.
 
View All Articles

Related Articles and Code:


 

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!