summaryrefslogtreecommitdiff
path: root/structures/stack.h
diff options
context:
space:
mode:
Diffstat (limited to 'structures/stack.h')
-rw-r--r--structures/stack.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/structures/stack.h b/structures/stack.h
new file mode 100644
index 0000000..171f8ae
--- /dev/null
+++ b/structures/stack.h
@@ -0,0 +1,32 @@
+#pragma once
+
+struct stack
+{
+ int inf;
+ stack *next;
+};
+
+void push(stack *&h, int x)
+{
+ stack *r = new stack;
+ r->inf = x;
+ r->next = h;
+ h = r;
+}
+
+int pop(stack *&h)
+{
+ int i = h->inf;
+ stack *r = h;
+ h = h->next;
+ delete r;
+ return i;
+}
+
+void reverse(stack *&h)
+{
+ stack *head1 = NULL;
+ while (h)
+ push(head1, pop(h));
+ h = head1;
+}