September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -1,9 +1,9 @@
let my_queue = Queue[Str]()
let my_queue = Queue()
my_queue.push! 'foo'
my_queue.push! 'bar'
my_queue.push! 'baz'
my_queue.push!('foo')
my_queue.push!('bar')
my_queue.push!('baz')
print my_queue.pop() # 'foo'
print my_queue.pop() # 'bar'
print my_queue.pop() # 'baz'
print my_queue.pop!() # 'foo'
print my_queue.pop!() # 'bar'
print my_queue.pop!() # 'baz'

View file

@ -1,22 +1,23 @@
MODULE UseQueue;
IMPORT StdLog,Queue,Boxes;
IMPORT
Queue,
Boxes,
StdLog;
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.Instance;
b: Boxes.Box;
BEGIN
q := Queue.New(10);
q.Push(Boxes.NewInteger(1));
q.Push(Boxes.NewInteger(2));
q.Push(Boxes.NewInteger(3));
b := q.Pop();
b := q.Pop();
q.Push(Boxes.NewInteger(4));
b := q.Pop();
b := q.Pop();
StdLog.String("Is empty:> ");StdLog.Bool(q.IsEmpty());StdLog.Ln
END Do;
END UseQueue.

View file

@ -1,24 +1,24 @@
import system'collections.
import extensions.
import system'collections;
import extensions;
program =
[
public program()
{
// Create a queue and "push" items into it
var queue := Queue new.
var queue := new Queue();
queue push:1.
queue push:3.
queue push:5.
queue.push:1;
queue.push:3;
queue.push:5;
// "Pop" items from the queue in FIFO order
console printLine(queue pop). // 1
console printLine(queue pop). // 3
console printLine(queue pop). // 5
console.printLine(queue.pop()); // 1
console.printLine(queue.pop()); // 3
console.printLine(queue.pop()); // 5
// To tell if the queue is empty, we check the count
console printLine("queue is ",(queue length == 0) iif("empty","nonempty")).
console.printLine("queue is ",(queue.Length == 0).iif("empty","nonempty"));
// If we try to pop from an empty queue, an exception
// is thrown.
queue pop | if(:e)[ console writeLine:"Queue empty.". ].
].
queue.pop() | on:(e){ console.writeLine:"Queue empty." }
}

View file

@ -1,20 +1,22 @@
/*REXX program demonstrates three queue operations: push, pop, empty. */
/*REXX program demonstrates four queueing operations: push, pop, empty, query. */
say ' Pushing five values to the stack.'
do j=1 for 4 /*loop to PUSH four values. */
call push j*10 /*PUSH (aka enqueue to stack). */
say 'pushed value:' j*10 /*echo the pushed value. */
if j\==3 then iterate /*also, insert a "null" entry. */
call push /*PUSH (aka enqueue to stack). */
say 'pushed a "null" value.' /*echo what was pushed. */
do j=1 for 4 /*a DO loop to PUSH four values. */
call push j * 10 /*PUSH (aka: enqueue to the stack).*/
say 'pushed value:' j * 10 /*echo the pushed value. */
if j\==3 then iterate /*Not equal 3? Then use a new number.*/
call push /*PUSH (aka: enqueue to the stack).*/
say 'pushed a "null" value.' /*echo what was pushed to the stack. */
end /*j*/
say ' Quering the stack (number of entries).'
say queued() ' entries in the stack.'
say ' Popping all values from the stack.'
do m=1 while \empty() /*EMPTY (returns TRUE if empty). */
call pop /*POP (aka dequeue from stack).*/
say m': popped value=' result /*echo the popped value. */
end /*m*/
do k=1 while \empty() /*EMPTY (returns TRUE [1] if empty).*/
call pop /*POP (aka: dequeue from the stack).*/
say k': popped value=' result /*echo the popped value. */
end /*k*/
say ' The stack is now empty.'
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────subroutines/functions/operators. */
push: queue arg(1); return /*REXX QUEUE is FIFO. */
pop: procedure; pull x; return x /*REXX PULL removes a stack item*/
empty: return queued()==0 /*returns the status of the stack*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
push: queue arg(1); return /*(The REXX QUEUE is FIFO.) */
pop: procedure; parse pull x; return x /*REXX PULL removes a stack item. */
empty: return queued()==0 /*returns the status of the stack. */

View file

@ -0,0 +1,6 @@
Public Sub fifo()
push "One"
push "Two"
push "Three"
Debug.Print pop, pop, pop, empty_
End Sub