GithubHelp home page GithubHelp logo

perilous_journey's Introduction

Perilous Journey

Ruby Linked List Demo

This is a demonstration of how one can use the expressiveness of Ruby to write a recursive linked list. The code in this repo is part of a blog post describing the development steps in this projcet.

This project draws heavily from the Turing School's Perilous Journey project.

Usage

  1. git clone
  2. cd perilous_journey
  3. Run the test suite - a. ruby test/node_test.rb b. ruby test/linked_list_test.rb

To build a linked list open 'irb' and:

irb
2.3.1 :001 > require './lib/linked_list'
 => true
2.3.1 :002 > list = LinkedList.new
 => #<LinkedList:0x007f822880d0e8 @head=nil>
2.3.1 :003 > list.append('Williams')
 => #<Node:0x007f8228804920 @surname="Williams", @next_node=nil>
2.3.1 :004 > list.append('Laws')
 => #<Node:0x007f8228834760 @surname="Laws", @next_node=nil>
2.3.1 :005 > list.append('Johnson')
 => #<Node:0x007f8228147470 @surname="Johnson", @next_node=nil>
2.3.1 :006 > list.to_string
 => "The Williams family, followed by the Laws family, followed by the Johnson family"
2.3.1 :007 > list.find(1,2)
 => "The Laws family, followed by the Johnson family"
2.3.1 :010 > list.includes?('Laws')
 => true
 2.3.1 :011 > list.insert(2, 'Roberts')
 => #<Node:0x007f822982cf50 @surname="Roberts", @next_node=#<Node:0x007f8228147470 @surname="Johnson", @next_node=nil>>
 2.3.1 :013 > list.to_string
 => "The Williams family, followed by the Laws family, followed by the Roberts family, followed by the Johnson family"
 2.3.1 :014 > list.pop
The Johnson family has died of dysentery
 => #<Node:0x007f8228147470 @surname="Johnson", @next_node=nil>
2.3.1 :015 > list.to_string
 => "The Williams family, followed by the Laws family, followed by the Roberts family"
 2.3.1 :016 > list.count
 => 3
2.3.1 :017 > list.append('Vader')
 => #<Node:0x007f8229814a90 @surname="Vader", @next_node=nil>
2.3.1 :018 > list.count
 => 4

perilous_journey's People

Contributors

jesse-spevack avatar

Stargazers

Thanos Bellos avatar

Forkers

nctruong

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.