Skip to content

A python library for implementation of various algorithms

License

Notifications You must be signed in to change notification settings

hope-miky/AddisAlgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AddisAlgo

AddisAlgo is python library to implement various algorithms and datastructures. The code is pure python and designed to use minimum memory and space. Algoeithms and data structures consisted in version 1.0 are:

  • Stack
  • Queue
  • Linear Search
  • Binary Search
  • Bubble Sort

Stack

The stack class will help implement the stack datatructure in user friendly way. The class consists 4 methods. In order to use the stack method we can import it like this.

from AddisAlgo import stack

Push

def push(self, value):
        if self.isFull() != True:
            self.top += 1
            self.source[self.top] = value
            return True
        else:
            print("The stack is full, cannot accept anymore values", "\n")
            return None

The push method checks if the stack/array is full and if not it will push the value to the array and update the top index. In order to use it we can use something like this by spacifing the length of the stack, which is in our case 7:

        stack = stack.stackClass(7)
        stack.push(1)

Pop

def pop(self):
        if self.isEmpty() != True:
            self.top -= 1
            return self.source[self.top + 1]
        else:
            print("The stack is empty, No more vlaues to pop", "\n")
            return None

The pop method checks if the stack/array is empty and if not it will pop a value from the array, return that value and update the top index. In order to use it we can use something like this:

        stack.pop()

isEmpty and isFull

Methods to check if the stack is empty and Full.

def isEmpty(self):
        return True if self.top == -1 else  False 

def isFull(self):
    return True if self.top == self.size -1 else  False 

About

A python library for implementation of various algorithms

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages