Code Monkey home page Code Monkey logo

linked-list's Introduction

Linked-List

Using object oriented design constructs, define a Node class and LinkedList class for a singly linked list. Each node has integer data value and a link to the next node. The linked list class has a head node and the following methods defined.

Getting Started

As usual with a python project, create a virtual environment:

python -m venv venv

Then activate the virtual environment

source venv/bin/activate

Then install the required packages.

pip install -r requirements.txt

Exercise

Design and implement the classes and the methods. Implement the methods within the Linked List class that are currently only contain pass.

Complete the following methods:

  • get_first - This method returns the value of the 1st node in the list (head). It returns None if the list is empty.
  • add_first - This method adds a new node with the given value to the head of the list.
  • search - This method returns True or False if the list contains the given value.
  • length - This method returns the size of the list.
  • get_at_index - This method returns the value of the node at the given index. It returns None if the list does not have that many elements.
  • get_last - This method returns the value of the last node in the list.
  • add_last - This method adds a new node to the rear of the list.
  • find_max - This method finds the largest value in the list, assuming you can use >, or < to compare each element in the list.
  • delete - This method deletes the node at the given index maintaining all the remaining elements in the same order.
  • reverse - This method reverses the list.

Going Further

There are a set of advanced methods you can choose to implement for additional practice. Tests are provided, but you will need to unskip them by removing the @pytest.mark.skip decorator.

For more practice complete the following methods:

  • find_middle_value - This method returns the value in the middle of the list (rounded down for even length lists).
  • find_nth_from_n - This method returns the value of the node which is nth from last in the list.
  • has_cycle- This method returns true if there is a loop in the list. I.e. somehow a node's next value is pointing to a prior node.

linked-list's People

Contributors

cheezitman avatar getlinn avatar shrutivanw avatar

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.