I am trying to write a clause for the following list handling rule : bubble(N,List,NewList) which binds NewList with the List having its Nth element brought to the front. e.g.bubble(3,[a,b,c,d,e],Ans). binds Ans to [c,a,b,d,e]
Here is my code. I don't know why it is not working. Can somebody helpppp me plsssss?? 10x
Here is my code. I don't know why it is not working. Can somebody helpppp me plsssss?? 10x
Code:
del(1,[H1|T],T).
del(N,[H|T],[H|Rest]):- NewN is N - 1,
del(NewN,T,Rest).
bubble(N,[H|T],[H1|New]):-del(N,[H|T],New).
bubble(N,[_|T],[H|Rest]):- bubble(N,T,Rest).