Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,29 +1,29 @@
on push(StackRef, value)
set StackRef's contents to {value} & StackRef's contents
return StackRef
set StackRef's contents to {value} & StackRef's contents
return StackRef
end push
on pop(StackRef)
set R to missing value
if StackRef's contents {} then
set R to StackRef's contents's item 1
set StackRef's contents to {} & rest of StackRef's contents
end if
return R
set R to missing value
if StackRef's contents {} then
set R to StackRef's contents's item 1
set StackRef's contents to {} & rest of StackRef's contents
end if
return R
end pop
on isStackEmpty(StackRef)
if StackRef's contents = {} then return true
return false
if StackRef's contents = {} then return true
return false
end isStackEmpty
set theStack to {}
repeat with i from 1 to 5
push(a reference to theStack, i)
log result
push(a reference to theStack, i)
log result
end repeat
repeat until isStackEmpty(theStack) = true
pop(a reference to theStack)
log result
pop(a reference to theStack)
log result
end repeat

View file

@ -23,9 +23,9 @@ int main()
printf("%d\n", i);
fprintf(stderr, "FIFO list %s\n",
( m_dequeue(&i, &head) ) ?
"had still an element" :
"is void!");
( m_dequeue(&i, &head) ) ?
"had still an element" :
"is void!");
exit(0);
}

View file

@ -3,20 +3,20 @@ IMPORT StdLog,Queue,Boxes;
PROCEDURE Do*;
VAR
q: Queue.Queue;
o: Boxes.Object;
BEGIN
q := Queue.NewQueue(6);
q.Push(Boxes.NewInteger(1));
q.Push(Boxes.NewInteger(2));
q.Push(Boxes.NewInteger(3));
o := q.Pop();
o := q.Pop();
q.Push(Boxes.NewInteger(4));
o := q.Pop();
o := q.Pop();
q.Push(Boxes.NewInteger(5));
o := q.Pop();
StdLog.String("Is empty: ");StdLog.Bool(q.IsEmpty());StdLog.Ln
q: Queue.Queue;
o: Boxes.Object;
BEGIN
q := Queue.NewQueue(6);
q.Push(Boxes.NewInteger(1));
q.Push(Boxes.NewInteger(2));
q.Push(Boxes.NewInteger(3));
o := q.Pop();
o := q.Pop();
q.Push(Boxes.NewInteger(4));
o := q.Pop();
o := q.Pop();
q.Push(Boxes.NewInteger(5));
o := q.Pop();
StdLog.String("Is empty: ");StdLog.Bool(q.IsEmpty());StdLog.Ln
END Do;
END UseQueue.

View file

@ -0,0 +1,11 @@
local :Q queue
!. empty Q
enqueue Q "HELLO"
enqueue Q 123
enqueue Q "It's a magical place"
!. empty Q
!. dequeue Q
!. dequeue Q
!. dequeue Q
!. empty Q
!. dequeue Q

View file

@ -1,14 +1,14 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% definitions of queue
empty(U-V) :-
unify_with_occurs_check(U, V).
unify_with_occurs_check(U, V).
push(Queue, Value, NewQueue) :-
append_dl(Queue, [Value|X]-X, NewQueue).
append_dl(Queue, [Value|X]-X, NewQueue).
pop([X|V]-U, X, V-U) :-
\+empty([X|V]-U).
\+empty([X|V]-U).
@ -17,32 +17,32 @@ append_dl(X-Y, Y-Z, X-Z).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% use of queue
queue :-
% create an empty queue
empty(Q),
format('Create queue ~w~n~n', [Q]),
% create an empty queue
empty(Q),
format('Create queue ~w~n~n', [Q]),
% add numbers 1 and 2
write('Add numbers 1 and 2 : '),
push(Q, 1, Q1),
push(Q1, 2, Q2),
% add numbers 1 and 2
write('Add numbers 1 and 2 : '),
push(Q, 1, Q1),
push(Q1, 2, Q2),
% display queue
format('~w~n~n', [Q2]),
% display queue
format('~w~n~n', [Q2]),
% pop element
pop(Q2, V, Q3),
% pop element
pop(Q2, V, Q3),
% display results
format('Pop : Value ~w Queue : ~w~n~n', [V, Q3]),
% display results
format('Pop : Value ~w Queue : ~w~n~n', [V, Q3]),
% test the queue
write('Test of the queue : '),
( empty(Q3) -> writeln('Queue empy'); writeln('Queue not empty')), nl,
% test the queue
write('Test of the queue : '),
( empty(Q3) -> writeln('Queue empy'); writeln('Queue not empty')), nl,
% pop the elements
write('Pop the queue : '),
pop(Q3, V1, Q4),
format('Value ~w Queue : ~w~n~n', [V1, Q4]),
% pop the elements
write('Pop the queue : '),
pop(Q3, V1, Q4),
format('Value ~w Queue : ~w~n~n', [V1, Q4]),
write('Pop the queue : '),
pop(Q4, _V, _Q5).
write('Pop the queue : '),
pop(Q4, _V, _Q5).