September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,62 +1,63 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
template queue :: type
|
||||
template queue<T>
|
||||
{
|
||||
array<type> theArray.
|
||||
int theTop.
|
||||
int theTale.
|
||||
T[] theArray;
|
||||
int theTop;
|
||||
int theTale;
|
||||
|
||||
explicit
|
||||
[
|
||||
theArray := type<>(8).
|
||||
theTop := 0.
|
||||
theTale := 0.
|
||||
]
|
||||
constructor()
|
||||
{
|
||||
theArray := new T[](8);
|
||||
theTop := 0;
|
||||
theTale := 0;
|
||||
}
|
||||
|
||||
bool empty
|
||||
= theTop == theTale.
|
||||
bool empty()
|
||||
= theTop == theTale;
|
||||
|
||||
push type:anObject
|
||||
[
|
||||
if (theTale > theArray length)
|
||||
[
|
||||
theArray := theArray reallocate(theTale).
|
||||
].
|
||||
push(T object)
|
||||
{
|
||||
if (theTale > theArray.Length)
|
||||
{
|
||||
theArray := theArray.reallocate(theTale)
|
||||
};
|
||||
|
||||
theArray[theTale] := anObject.
|
||||
theArray[theTale] := object;
|
||||
|
||||
theTale += 1.
|
||||
]
|
||||
theTale += 1
|
||||
}
|
||||
|
||||
type pop
|
||||
[
|
||||
T pop()
|
||||
{
|
||||
if (theTale == theTop)
|
||||
[ InvalidOperationException new:"Queue is empty"; raise ].
|
||||
{ InvalidOperationException.new:"Queue is empty".raise() };
|
||||
|
||||
type item := theArray[theTop].
|
||||
T item := theArray[theTop];
|
||||
|
||||
theTop += 1.
|
||||
theTop += 1;
|
||||
|
||||
^ item
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
queue<int> q := queue<int>().
|
||||
q push(1).
|
||||
q push(2).
|
||||
q push(3).
|
||||
console printLine(q pop).
|
||||
console printLine(q pop).
|
||||
console printLine(q pop).
|
||||
console printLine("a queue is ", q empty; iif("empty","not empty")).
|
||||
console print("Trying to pop:").
|
||||
try(q pop)
|
||||
public program()
|
||||
{
|
||||
queue<int> q := new queue<int>();
|
||||
q.push(1);
|
||||
q.push(2);
|
||||
q.push(3);
|
||||
console.printLine(q.pop());
|
||||
console.printLine(q.pop());
|
||||
console.printLine(q.pop());
|
||||
console.printLine("a queue is ", q.empty().iif("empty","not empty"));
|
||||
console.print("Trying to pop:");
|
||||
try
|
||||
{
|
||||
on(Exception e)
|
||||
[
|
||||
console printLine(e message)
|
||||
]
|
||||
q.pop()
|
||||
}
|
||||
].
|
||||
catch(Exception e)
|
||||
{
|
||||
console.printLine(e.Message)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue