GithubHelp home page GithubHelp logo

data-structures's Introduction

data-structures

This repository contains sample code for a number of classic data structures implemented in Python.

Use the Doubly Linked List or cases where a user may need to reference a previous item in the list from any given item, or where a user may need to iterate through the list in reverse order. Otherwise, use the slightly faster Singly Linked List.

Singly Linked List: Module linked_list.py contains a recursively generated linked list class (Linked_List).

Stack: Module stack.py leverages the linked_list module to build methods for generating a stack, as well as adding and removing items.

Doubly Linked List: Module dbl_linked_list.py contains a DblLinkedList class with pop, shift, insert, append and remove methods. It also contains a Node class, which DblLinkedList uses to hold its values.

Queue: Module new_queue.py contains a Queue class with enqueue, dequeue, and size methods, as well as a peek method that allows the user to get the value of the next item in the queue without popping it. The Queue class imports the DblLinkedList class described above, and most of its methods are composed from this class.

Deque: Module new_deque.py contains a Deque class with methods for appending to both ends of the deque, removing items from each end of the deque, "peeking" at the values of the items on each end, and calculating the size of the deque. The Deque class imports the DblLinkedList class, and most of its methods are composed from this class.

BinHeap: Module binheap.py contains a BinHeap class which sorts itself in binary heap fashion. Each node has two children, both of which must be of lesser value than the parent. The class has a pop method which removes the root at the top of the heap, and a push which appends a new value to the end of the heap. In both cases, the heap immediately re-arranges itself.

PriorityQueue: Module priorityq.py defines a PriorityQ class which sorts contents by the priority with which they were added. In Queue style, it then orders items by the order in which they were added (first in, first out). It has an insert method to add to the Priority Queue, and a pop method to remove and return the first item by priority. The peek method shows this same value.

Resources:

https://www.codefellows.org/blog/implementing-a-singly-linked-list-in-python

http://interactivepython.org/runestone/static/pythonds/BasicDS/ImplementinganUnorderedListLinkedLists.html

http://stackoverflow.com/questions/31333462/finding-the-length-of-a-linked-list-in-python

https://en.wikipedia.org/wiki/Linked_list

data-structures's People

Contributors

ksgifford avatar willweatherford avatar

Watchers

 avatar

Forkers

willweatherford

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.