From e63ebe7b952fdcf3a7f25997792bab2c88f584c9 Mon Sep 17 00:00:00 2001 From: Bansikah Date: Thu, 7 Dec 2023 20:11:05 +0100 Subject: [PATCH 1/2] feat(readme) add documentation for alogithm stack class --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 38c9d34..077737a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,35 @@ # Python-Data-Structures-and-Algorithms +# Stack class + +This is a Python class that implements a stack data structure. A stack is a linear data structure in which elements are added and removed from one end, called the top. The stack follows the last-in, first-out (LIFO) principle, which means that the last element added to the stack is the first element to be removed. + +The `Stack` class has the following methods: + +* `__init__(self)`: Initializes the stack. +* `is_empty(self)`: Returns True if the stack is empty, False otherwise. +* `push(self, item)`: Adds an item to the stack. +* `pop(self)`: Removes an item from the stack and returns it. +* `peek(self)`: Returns the top item on the stack without removing it. +* `size(self)`: Returns the number of items in the stack. +* `__str__(self)`: Returns a string representation of the stack. + +Here is an example of how to use the `Stack` class: +python +>>> s = Stack() +>>> print(s) +[] +>>> print(s.is_empty()) +True +>>> s.push(1) +>>> s.push(2) +>>> s.push(3) +>>> print(s) +[1, 2, 3] +>>> print(s.pop()) +3 +>>> print(s.peek()) +2 +>>> print(s.size()) +2 +The `Stack` class is a useful data structure for implementing a variety of algorithms, such as the infix-to-postfix conversion algorithm and the binary search algorithm. \ No newline at end of file From c4f6aa7dc96f2619d07b07a2d4f3fad5c6209a82 Mon Sep 17 00:00:00 2001 From: Bansikah Date: Thu, 7 Dec 2023 20:35:32 +0100 Subject: [PATCH 2/2] added vscode in git ignore file --- .gitignore | 1 + README.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 510c73d..5450fb8 100644 --- a/.gitignore +++ b/.gitignore @@ -112,3 +112,4 @@ dmypy.json # Pyre type checker .pyre/ +*.vscode diff --git a/README.md b/README.md index 077737a..9c45243 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,5 @@ True 2 >>> print(s.size()) 2 -The `Stack` class is a useful data structure for implementing a variety of algorithms, such as the infix-to-postfix conversion algorithm and the binary search algorithm. \ No newline at end of file +The `Stack` class is a useful data structure for implementing a variety of algorithms, such as the infix-to-postfix conversion algorithm and the binary search algorithm. +You can view code here [stack class](/Starting Files/a_star.py) \ No newline at end of file