Git Product home page Git Product logo

linked_list's Introduction

Create a linked list (singly-linked)

By now, you're used to creating an array in Ruby with literal notation, my_arr = [1, 1, 1] But another way to do the same thing is with the syntax my_arr = Array.new(3, 1) In both cases, you are instantiating a new instance of Ruby's built-in Array class and populating it with some values. Unfortunately, Ruby and Javascript do not have built-in (Primitive) classes for the Linked List data structure (even though linked lists are everywhere!) so we need to build our own LinkedList and Node classes in order to create this data structure in the languages we know.

  • You will need a LinkedList class which can be instantiated with or without a @head Node object.
  • Your LinkedList class should have 5 instance methods:
    • one which adds a new node to the end of the list (or makes it the head if it's the first node)
    • one which allows a node to be inserted at an index,
    • one which allows a node to be deleted at an index,
    • one which retrieves a node at an index, and
    • one which prints the whole linked list
  • You will need a Node class which holds data and a pointer to the next node.
  • You can choose to put methods in your Node class which allows insertion and deletion of an adjacent node, but be careful if you go this route!
  • Show me it works!
  • BONUS: Create a .create_from_array class method in LinkedList
  • DOUBLE BONUS: Make your .create_from_array class method run in O(n) time

linked_list's People

Contributors

betalantz 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.