summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-10 22:18:52 +0400
committerAndrew <saintruler@gmail.com>2021-02-10 22:18:52 +0400
commit83f659d36b8c64209b72e70583cb4f0a6852e7be (patch)
treedabe841ec5bbb2a1aac6301f3e4dbb6774ca7860
parentee1fd8e4b8090cbc107af5c8d05fa1979f43f9fd (diff)
Заменил run.sh на Makefile и вынес реализацию стека с функциями в отдельный файл
-rw-r--r--.gitignore1
-rw-r--r--structures/Makefile9
-rwxr-xr-xstructures/run.sh7
-rw-r--r--structures/stack.h32
-rw-r--r--structures/task5.cpp33
5 files changed, 44 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f47cb20
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.out
diff --git a/structures/Makefile b/structures/Makefile
new file mode 100644
index 0000000..8694df6
--- /dev/null
+++ b/structures/Makefile
@@ -0,0 +1,9 @@
+CXX=g++
+CFLAGS=-Wall
+COMPILE=$(CXX) $(CFLAGS)
+
+task5:
+ $(COMPILE) -o task.out task5.cpp
+
+clean:
+ rm task.out
diff --git a/structures/run.sh b/structures/run.sh
deleted file mode 100755
index f076a51..0000000
--- a/structures/run.sh
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-
-name="${1%%.*}"
-g++ -Wall -o $name.out $name.cpp
-./$name.out
-rm $name.out
-
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;
+}
diff --git a/structures/task5.cpp b/structures/task5.cpp
index 72e1381..f182625 100644
--- a/structures/task5.cpp
+++ b/structures/task5.cpp
@@ -1,36 +1,7 @@
#include <iostream>
-using namespace std;
-
-struct stack
-{
- int inf;
- stack *next;
-};
+#include "stack.h"
-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;
-}
+using namespace std;
stack *result(stack *&h)
{