aboutsummaryrefslogtreecommitdiff
path: root/other/browser_history.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
committerJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
commit7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch)
treeeb7a24ee2067f92245c57bb118e85a1baf15df50 /other/browser_history.cpp
parent5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff)
downloadleetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz
leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip
chore: move cpp and rust code to directory
Diffstat (limited to 'other/browser_history.cpp')
-rw-r--r--other/browser_history.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/other/browser_history.cpp b/other/browser_history.cpp
new file mode 100644
index 0000000..df7d3cd
--- /dev/null
+++ b/other/browser_history.cpp
@@ -0,0 +1,45 @@
+// 1472. Design Browser History
+#include "leetcode.h"
+
+/*
+ * you have a browser of one tab where you start on the homepage and can visit
+ * another url, get back in the history number of steps or move forward in the
+ * history number of steps. implement BrowserHistory class (they're self
+ * explantory)
+ */
+
+class BrowserHistory {
+public:
+ BrowserHistory(string homepage) { curr = homepage; }
+ void visit(string url) {
+ h_forward = stack<string>();
+ h_back.push(curr);
+ curr = url;
+ }
+ string back(int steps) {
+ while (--steps >= 0 && !h_back.empty()) {
+ h_forward.push(curr);
+ curr = h_back.top();
+ h_back.pop();
+ }
+ return curr;
+ }
+ string forward(int steps) {
+ while (--steps >= 0 && !h_forward.empty()) {
+ h_back.push(curr);
+ curr = h_forward.top();
+ h_forward.pop();
+ }
+ return curr;
+ }
+
+private:
+ stack<string> h_back, h_forward;
+ string curr;
+};
+
+int main() {
+ BrowserHistory *obj = new BrowserHistory("https.xyz");
+ string param_2 = obj->back(1);
+ string param_3 = obj->forward(1);
+}