Skip to content

Commit 7eb2445

Browse files
committed
Revision 1 (Amaras)
1 parent c929114 commit 7eb2445

File tree

4 files changed

+5
-56
lines changed

4 files changed

+5
-56
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ This file lists everyone, who contributed to this repo and wanted to show up her
6464
- K. Shudipto Amin
6565
- Peanutbutter_Warrior
6666
- Thijs Raymakers
67+
- Michael Ciccotosto-Camp

contents/stacks_and_queues/code/python/queue.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,14 @@
22

33
__author__ = "Michael Ciccotosto-Camp"
44

5-
import abc
6-
75
from collections.abc import Sized
86
from typing import TypeVar, Generic
97

108

119
T = TypeVar("T")
1210

1311

14-
class IQueue(Generic[T], Sized, abc.ABC):
15-
@abc.abstractmethod
16-
def dequeue(self) -> T:
17-
"""
18-
Removes the first element from the queue and returns it.
19-
"""
20-
...
21-
22-
@abc.abstractmethod
23-
def enqueue(self, element: T) -> int:
24-
"""
25-
Add an element at the end of the queue and returns the
26-
new size of the queue.
27-
"""
28-
...
29-
30-
@abc.abstractmethod
31-
def front(self) -> T:
32-
"""
33-
Returns the first element in the queue without removing it.
34-
"""
35-
...
36-
37-
38-
class Queue(IQueue[T]):
12+
class Queue(Generic[T], Sized):
3913
def __init__(self) -> None:
4014
self.__list: list[T] = list()
4115

contents/stacks_and_queues/code/python/Stack.py renamed to contents/stacks_and_queues/code/python/stack.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,14 @@
22

33
__author__ = "Michael Ciccotosto-Camp"
44

5-
import abc
6-
75
from collections.abc import Sized
86
from typing import TypeVar, Generic
97

108

119
T = TypeVar("T")
1210

1311

14-
class IStack(Generic[T], Sized, abc.ABC):
15-
@abc.abstractmethod
16-
def pop(self) -> T:
17-
"""
18-
Removes the last element from the stack and returns it.
19-
"""
20-
...
21-
22-
@abc.abstractmethod
23-
def push(self, element: T) -> int:
24-
"""
25-
Adds an element to the end of the stack and returns the
26-
new length of the stack.
27-
"""
28-
...
29-
30-
@abc.abstractmethod
31-
def top(self) -> T:
32-
"""
33-
Returns the first element of the stack.
34-
"""
35-
...
36-
37-
38-
class Stack(IStack[T]):
12+
class Stack(Generic[T], Sized):
3913
def __init__(self) -> None:
4014
self.__list: list[T] = []
4115

contents/stacks_and_queues/stacks_and_queues.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Stacks and Queues are two sides of the same coin in computer science. They are both simple data structures that hold multiple elements, but allow you to use a single element at a time. The biggest difference between the two structures is the order in which you can access the elements in the data structure.
44

5-
In _stacks_, data follows _Last In, First Out_ (LIFO), which basically means that whichever element you put in last will be the first element you take out. It acts exactly like a stack in real life. If you put a book on a stack of other books, the first book you will look at when sifting through the stack will be the book you just put on the stack.
5+
In *stacks*, data follows *Last In, First Out* (LIFO), which basically means that whichever element you put in last will be the first element you take out. It acts exactly like a stack in real life. If you put a book on a stack of other books, the first book you will look at when sifting through the stack will be the book you just put on the stack.
66

7-
In _Queues_, data follows _First In, First Out_ (FIFO), which means that whichever element you put in first will be the first element you take out. Imagine a queue of people. It would be unfair if the first person in line for groceries were not the first person to receive attention once the attendant finally shows up.
7+
In *Queues*, data follows *First In, First Out* (FIFO), which means that whichever element you put in first will be the first element you take out. Imagine a queue of people. It would be unfair if the first person in line for groceries were not the first person to receive attention once the attendant finally shows up.
88

99
For the most part, though, queues and stacks are treated the same way. There must be a way to:
1010

0 commit comments

Comments
 (0)