2021-03-23 19:35:13 +00:00
|
|
|
module misc.utils;
|
|
|
|
|
|
|
|
import std.string : cmp;
|
2022-12-11 19:14:31 +00:00
|
|
|
import std.array : replace;
|
2021-03-23 19:35:13 +00:00
|
|
|
|
|
|
|
public bool isPresent(string[] arr, string t)
|
|
|
|
{
|
|
|
|
foreach(string j; arr)
|
|
|
|
{
|
|
|
|
if(cmp(j, t) == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-03-28 18:48:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given character is a letter
|
|
|
|
*/
|
|
|
|
public bool isCharacterAlpha(char character)
|
|
|
|
{
|
|
|
|
return (character >= 65 && character <= 90) || (character >= 97 && character <= 122);
|
2021-03-28 18:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given character is a number
|
|
|
|
*/
|
|
|
|
public bool isCharacterNumber(char character)
|
|
|
|
{
|
|
|
|
return (character >= 48 && character <= 57);
|
2022-12-11 19:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-12 14:39:57 +00:00
|
|
|
|
2022-12-12 14:39:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
template Stack(T)
|
|
|
|
{
|
|
|
|
public final class Stack
|
|
|
|
{
|
|
|
|
import std.container.slist : SList;
|
|
|
|
|
|
|
|
private SList!(T) queue;
|
|
|
|
|
|
|
|
public void push(T item)
|
|
|
|
{
|
|
|
|
queue.insertFront(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public T pop()
|
|
|
|
{
|
|
|
|
//FIXME: Handling for emoty stack
|
|
|
|
T stackTop = queue.front();
|
|
|
|
queue.removeFront();
|
|
|
|
|
|
|
|
return stackTop;
|
|
|
|
}
|
|
|
|
}
|
2021-03-23 19:35:13 +00:00
|
|
|
}
|