Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
63
Task/Queue-Definition/Elena/queue-definition.elena
Normal file
63
Task/Queue-Definition/Elena/queue-definition.elena
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import extensions;
|
||||
|
||||
template queue<T>
|
||||
{
|
||||
T[] theArray;
|
||||
int theTop;
|
||||
int theTale;
|
||||
|
||||
constructor()
|
||||
{
|
||||
theArray := new T[](8);
|
||||
theTop := 0;
|
||||
theTale := 0;
|
||||
}
|
||||
|
||||
bool empty()
|
||||
= theTop == theTale;
|
||||
|
||||
push(T object)
|
||||
{
|
||||
if (theTale > theArray.Length)
|
||||
{
|
||||
theArray := theArray.reallocate(theTale)
|
||||
};
|
||||
|
||||
theArray[theTale] := object;
|
||||
|
||||
theTale += 1
|
||||
}
|
||||
|
||||
T pop()
|
||||
{
|
||||
if (theTale == theTop)
|
||||
{ InvalidOperationException.new:"Queue is empty".raise() };
|
||||
|
||||
T item := theArray[theTop];
|
||||
|
||||
theTop += 1;
|
||||
|
||||
^ item
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
q.pop()
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
console.printLine(e.Message)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue