From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/peeking_iterator.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 other/peeking_iterator.cpp (limited to 'other/peeking_iterator.cpp') diff --git a/other/peeking_iterator.cpp b/other/peeking_iterator.cpp new file mode 100644 index 0000000..1c4d0b9 --- /dev/null +++ b/other/peeking_iterator.cpp @@ -0,0 +1,32 @@ +#include "leetcode.h" + +class Iterator { + struct Data; + Data *data; + +public: + Iterator(const vector &nums); + Iterator(const Iterator &iter); + int next(); + bool hasNext() const; +}; + +class PeekingIterator : public Iterator { +public: + int nextVal; + PeekingIterator(const vector &nums) : Iterator(nums) { + nextVal = Iterator::next(); + } + int peek() { return nextVal; } + int next() { + int tmp = nextVal; + if (Iterator::hasNext()) + nextVal = Iterator::next(); + else + nextVal = NULL; + return tmp; + } + bool hasNext() const { return (nextVal != NULL); } +}; + +int main() {} -- cgit v1.2.3