Slides on lists. Operation on lists

Слайд 2

Operation on lists.

Search of elements in lists.
find_it (3, [1,2,3,4,5]).
_________________
find_it (Head,

Operation on lists. Search of elements in lists. find_it (3, [1,2,3,4,5]). _________________
[Head|_]).
___________________
find_it (Head, [Head |_].
find_it (Head, [_,Tail]) :- find it (Head, Tail).

Division of lists
Split (Middle,L,L1,L2).
Split(40, [30,50,20,25,65,95],L1,L2).
split(Middle, [Head|Tail], [Head| LI],L2) :-
Head <= Middle,
split(Middle,Tail,Ll,L2).
split(Middle, [Head|Tail],L1, [Head|L2]) :-
Head > Middle,
split(Middle,Tail, L1,L2),
split (_,[],[],[]).

Слайд 3


Attachment of lists.
L1 =[1,2,3] , L2 =[4,5] :
append([], L,L).
append([N |L1],L2,[N

Attachment of lists. L1 =[1,2,3] , L2 =[4,5] : append([], L,L). append([N
|L3]) :- append(LI,L2,L3).
L1= [1,2,3] и L2= [4,5],
append( [] ,L,L) .
append([],[4,5],_).
append([], [4,5], [4,5]).
Steps of the given process can be presented so:
append([], [4,5], [4,5]) ‘
append([3], [4,5], [3,4,5]|
append([2,3], [4,5], [2,3,4,5])
append([1,2,3], [4,5], [1,2,3,4,5])

Operation on lists.

Слайд 4

Operation on lists.

Sorting of lists.
[4,7,3,9] [3,4,7,9],
insert_sort([],[]).
insert_sort ([Х]| Tail], Sorted__list)

Operation on lists. Sorting of lists. [4,7,3,9] [3,4,7,9], insert_sort([],[]). insert_sort ([Х]| Tail],
:- insert_sort (Tail,Sorted__Tail),
insert(X,Sorted_Tail,Sorted_list).
insert(X|Y Sorted_list] , [Y | Sorted_list 1)) :- asc_order(X,Y), ! ,
insert(X,Sorted_list,Sorted_list1) .
insert(X,Sorted_list,[X|Sorted_list]).
asc_order(X,Y) :- X>Y.
__________________
insert(4, [3,7,9], [3,4,7,9]) .
insert_sort([4,7,3,9],[3,4,7,9]).
Имя файла: Slides-on-lists.-Operation-on-lists.pptx
Количество просмотров: 58
Количество скачиваний: 0