diff options
| author | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 19:35:12 +0800 |
|---|---|---|
| committer | Lam Wei Lun <weilun.lam@gmail.com> | 2026-01-21 19:35:12 +0800 |
| commit | e8ef3454880b92a5485a339b3b6fe7b64cfe5305 (patch) | |
| tree | 7e82fc6cb9ef2f81919a383ff83c6b79acd6a764 /std/queue.zc | |
| parent | 8144aef45d5db22ab2895b41448cd76bf01e05cc (diff) | |
Add length, clear, is_empty to Stack and Queue
Diffstat (limited to 'std/queue.zc')
| -rw-r--r-- | std/queue.zc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/std/queue.zc b/std/queue.zc index 2bbcfaa..31e5dbd 100644 --- a/std/queue.zc +++ b/std/queue.zc @@ -38,8 +38,6 @@ impl Queue<T> { self.cap = self.cap * 2; self.data = realloc(self.data, sizeof(T) * self.cap); } - - // Assigns it at the back of self.data[self.len] = value; self.len = self.len + 1; } @@ -56,6 +54,18 @@ impl Queue<T> { } return Option<T>::None(); } + + fn length(self) -> usize { + return self.len; + } + + fn clear(self) { + self.len = 0; + } + + fn is_empty(self) -> bool { + return self.len == 0; + } } impl Drop for Queue<T> { |
