GithubHelp home page GithubHelp logo

jaenwawe / phase-4-data-structures-reverse-doubly-linked-list Goto Github PK

View Code? Open in Web Editor NEW

This project forked from learn-co-curriculum/phase-4-data-structures-reverse-doubly-linked-list

0.0 0.0 0.0 6 KB

License: Other

Ruby 100.00%

phase-4-data-structures-reverse-doubly-linked-list's Introduction

Reverse a Doubly Linked List

Learning Goals

  • Build a doubly linked list and use it to solve an algorithm

Introduction

At this point we've learned how to solve algorithms with singly linked lists, and learned what doubly linked lists are, so it's time to put that knowledge to use and solve an algorithm with a doubly linked list!

Fork and clone this lab; you'll be coding in the lib folder. You can run the tests at any point using learn test to check your work.

Instructions

Write a method LinkedList#reverse! that reverses the list in place, so the head is the new tail, the tail is the new head, and all of the prev_node and next_node attributes of each node in the list point to the correct nodes.

For example:

  • Input: 6 <--> 7 <--> 8

  • Output: 8 <--> 7 <--> 6

  • Input: 11 <--> 18 <--> 19 <--> 94

  • Output: 94 <--> 19 <--> 18 <--> 11

  • Input: 41 <--> 101 <--> 8 <--> 28 <--> 32

  • Output: 32 <--> 28 <--> 8 <--> 101 <--> 41

Bonus

Try to solve the problem recursively!

Hint: You might want to create a recursive helper method reverse_node instead of trying to use the reverse! method recursively.

phase-4-data-structures-reverse-doubly-linked-list's People

Contributors

graciemcguire avatar ihollander 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.