Commits

Yujie Wu  committed 1818d89

Modified some rules to be more prolog-ic.

  • Participants
  • Parent commits c662bc2
  • Branches feature/set

Comments (0)

Files changed (1)

 partition( [],            _,     [],            []               ).
 partition( [Elem | Tail], Pivot, [Elem | Less],         Greater  ) :- Elem <  Pivot, partition( Tail, Pivot, Less, Greater ).
 partition( [Elem | Tail], Pivot,         Less,  [Elem | Greater] ) :- Elem >  Pivot, partition( Tail, Pivot, Less, Greater ).
-partition( [Elem | Tail], Pivot,         Less,          Greater  ) :- Elem == Pivot, partition( Tail, Pivot, Less, Greater ).
+partition( [Elem | Tail], Elem,          Less,          Greater  ) :-                partition( Tail, Elem,  Less, Greater ).
 
 quick_sort( [],   []     ).
 quick_sort( List, Sorted ) :-
 add( Item, [],            [Item]               ).
 add( Item, [Elem | Tail], [      Elem | Added] ) :- Item  > Elem, add( Item, Tail, Added ).
 add( Item, [Elem | Tail], [Item, Elem | Tail ] ) :- Item  < Elem.
-add( Item, [Elem | Tail], [      Elem | Tail ] ) :- Item == Elem.
+add( Item, [Item | Tail], [      Item | Tail ] ).
 
 
 
 del( _,    [],            []             ).
 del( Item, [Elem | Tail], [Elem | Added] ) :- Item  > Elem, del( Item, Tail, Added ).
 del( Item, [Elem | Tail], [Elem | Tail ] ) :- Item  < Elem.
-del( Item, [Elem | Tail],         Tail   ) :- Item == Elem.
+del( Item, [Item | Tail],         Tail   ).
 
 
 
 
 % True if the set contains the item.
-has( _,    []            ) :- fail.
 has( Item, [Elem | Tail] ) :- Item  > Elem, has( Item, Tail ).
-has( Item, [Elem | _   ] ) :- Item  < Elem, fail.
-has( Item, [Elem | _   ] ) :- Item == Elem.
+has( Item, [Item | _   ] ).