Welcome to pyDS’s documentation!

Intro

pyDS is a python module consisting of various data structure and algorithm implementations.

Usage:

from pyDS.stack import Stack
from pyDS.usecase.stack import bracketBalanced, decimalBaseConvert

stack = Stack()

stack.push(2)
stack.push(5)

print(stack)
# 2 5

print(stack.peek())
# 5

print(stack.pop())
# 5

print(stack.peek())
# 2

pyDS

pyDS package

Subpackages

pyDS.usecase package
Submodules
pyDS.usecase.stack module
pyDS.usecase.stack.bracketBalanced(expression)[source]

Check if an expression is balanced.

An expression is balanced if all the opening brackets(i.e. ‘(, {, [‘) have a corresponding closing bracket(i.e. ‘), }, ]’).

Args:
expression (str) : The expression to be checked.
Returns:
bool: True if expression is balanced. False if not balanced.
pyDS.usecase.stack.decimalBaseConvert(number, base=2)[source]

Convert decimal numbers.

Convert the base of a decimal number to another base.

Args:

number (int): The number to be converted. base (int, optional): The base to convert the number to.

Defaults to 2. Minimum value 2. Maximum value 16.
Returns:
str: The string representation of the converted number.
Module contents

Submodules

pyDS.linked_list module

class pyDS.linked_list.LinkedList[source]

Bases: object

An implementation of the Linked List data structure.

append(item)[source]

Add item to the end of the Linked List.

Args:
item: The item to be inserted.
delete(item)[source]

Delete an item from the Linked List.

push(item)[source]

Add item to the front of the Linked List.

Args:
item: The item to be inserted.
reverse()[source]

Reverse the items of the Linked List.

class pyDS.linked_list.Node(data)[source]

Bases: object

Building Block of Linked List.

pyDS.queue module

class pyDS.queue.Queue[source]

Bases: object

An implementation of the Queue data strucutre.

dequeue()[source]

Remove item from queue.

Returns:
The first item from the Queue. Raises IndexError if Queue empty.
enqueue(item)[source]

Add item to Queue.

Args:
item: The item to be inserted.
front()[source]

Return the first Queue item.

Returns:
The first item from the Queue. Raises IndexError if Queue empty.
is_empty()[source]

Check queue is empty.

Returns:
True if Queue is empty, False otherwise.
rear()[source]

Return the last Queue item.

Returns:
The last item from the Queue. Raises IndexError if Queue empty.

pyDS.stack module

class pyDS.stack.Stack[source]

Bases: object

An implementation of the stack data structure.

is_empty()[source]

Return whether the stack is empty.

peek()[source]

Return the top item from the Stack.

pop()[source]

Remove an item from the Stack.

push(item)[source]

Add an item to the stack.

Module contents

Indices and tables