Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55c2ed2

Browse filesBrowse files
committed
update stack
1 parent 20f39aa commit 55c2ed2
Copy full SHA for 55c2ed2

File tree

10 files changed

+111
-8
lines changed
Filter options

10 files changed

+111
-8
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Remember that each data has its own trade-offs. And you need to pay attention mo
2424
* `B` [Linked List](data-structures/LinkedList)
2525
* `B` [Doubly Linked List](data-structures/DoublyLinkedList)
2626
* `B` [Queue](data-structures/Queue)
27+
* `B` [Stack](data-structures/Stack)
28+
2729

2830
## Algorithms
2931

‎README.zh-CN.md

Copy file name to clipboardExpand all lines: README.zh-CN.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* `B` [单链表](data-structures/LinkedList)
2222
* `B` [双链表](data-structures/DoublyLinkedList)
2323
* `B` [队列](data-structures/Queue)
24+
* `B` [](data-structures/Stack)
25+
2426

2527

2628
## 算法

‎data-structures/Queue/include/Queue.h

Copy file name to clipboardExpand all lines: data-structures/Queue/include/Queue.h
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#ifndef QUEUE_H
22
#define QUEUE_H
3-
3+
/*
4+
* We're going to implement Queue based on LinkedList since the two
5+
* structures are quite similar. Namely, they both operate mostly on
6+
* the elements at the beginning and the end. Compare push/pop
7+
* operations of Queue with push_back/pop_front operations of LinkedList.
8+
*/
49
#include <stdexcept>
510
#include <cstddef>
611
#include "../../LinkedList/include/LinkedList.h"
712

8-
/*
9-
We're going to implement Queue based on LinkedList since the two
10-
structures are quite similar. Namely, they both operate mostly on
11-
the elements at the beginning and the end. Compare push/pop
12-
operations of Queue with push_back/pop_front operations of LinkedList.
13-
*/
14-
1513
template <typename T>
1614
class Queue{
1715
public:

‎data-structures/Stack/CMakeLists.txt

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Specify the minimum version of CMake required
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
# Project name and version
5+
project(StackProject VERSION 1.0)
6+
7+
# Set C++ standard
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_CXX_STANDARD_REQUIRED True)
10+
11+
# Include directories
12+
include_directories(include)
13+
14+
# Output executables to the 'bin' directory
15+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
16+
17+
# Add the test executable
18+
add_executable(test_Stack __test__/test_Stack.cpp)
19+
20+
# Link the LinkedList library to the test executable
21+
target_link_libraries(test_Stack)

‎data-structures/Stack/README.md

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
3+
在计算机科学中, 一个 **栈(stack)** 是一种抽象数据类型,用作表示元素的集合,具有两种主要操作:
4+
5+
* **push**, 添加元素到栈的顶端(末尾);
6+
* **pop**, 移除栈最顶端(末尾)的元素.
7+
8+
以上两种操作可以简单概括为“后进先出(LIFO = last in, first out)”。
9+
10+
此外,应有一个 `peek` 操作用于访问栈当前顶端(末尾)的元素。
11+
12+
"栈"这个名称,可类比于一组物体的堆叠(一摞书,一摞盘子之类的)。
13+
14+
栈的 push 和 pop 操作的示意
15+
16+
![Stack](./assets/stack.jpeg)
17+
18+
*Made with [okso.app](https://okso.app)*
19+
20+
## 参考
21+
22+
- [Wikipedia](https://en.wikipedia.org/wiki/Stack_(abstract_data_type))
23+
- [YouTube](https://www.youtube.com/watch?v=wjI1WNcIntg&list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8&index=3&)
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../include/Stack.h"
150 KB
Loading

‎data-structures/Stack/build.sh

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Create the build directory if it doesn't exist
4+
if [ ! -d "build" ]; then
5+
mkdir build
6+
fi
7+
8+
# Run CMake in the build directory
9+
cd build
10+
cmake ..
11+
12+
# Build the project using make
13+
make
14+
15+
# Return to the project root directory
16+
cd ..
17+
18+
# Inform the user where the executable can be found
19+
echo "Build complete. Executable located in the ./bin directory."

‎data-structures/Stack/clean.sh

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Remove build and bin directories
4+
rm -rf build
5+
rm -rf bin
6+
7+
echo "Clean complete. Build and bin directories removed."

‎data-structures/Stack/include/Stack.h

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef STACK_H
2+
#define STACK_H
3+
/*
4+
* We're going to implement Stack based on LinkedList since these
5+
* tructures are quite similar. Compare push/pop operations of the Stack
6+
* with push_front/pop_front operations of LinkedList.
7+
*/
8+
#include "../../LinkedList/include/LinkedList.h"
9+
#include <cstddef>
10+
#include <stdexcept>
11+
12+
template <typename T>
13+
class Stack{
14+
public:
15+
// Capacity
16+
bool empty();
17+
size_t size();
18+
// Add
19+
void push(T& value);
20+
// Delete
21+
void pop();
22+
// Check
23+
void top();
24+
private:
25+
LinkedList<T> list;
26+
};
27+
28+
29+
30+
#endif // STACK_H

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.