7 kyu

Linked Lists - Move Node

711 of 1,903JDeBolt

Description:

Linked Lists - Move Node

Write a MoveNode() function which takes the node from the front of the source list and moves it to the front of the destintation list. You should throw an error when the source list is empty. For simplicity, we use a Context object to store and return the state of the two linked lists. A Context object containing the two mutated lists should be returned by moveNode.

MoveNode() is a handy utility function to have for later problems.

JavaScript

var source = 1 -> 2 -> 3 -> null
var dest = 4 -> 5 -> 6 -> null
moveNode(source, dest).source === 2 -> 3 -> null
moveNode(source, dest).dest === 1 -> 4 -> 5 -> 6 -> null

Python

source = 1 -> 2 -> 3 -> None
dest = 4 -> 5 -> 6 -> None
move_node(source, dest).source == 2 -> 3 -> None
move_node(source, dest).dest == 1 -> 4 -> 5 -> 6 -> None

Ruby

source = 1 -> 2 -> 3 -> nil
dest = 4 -> 5 -> 6 -> nil
move_node(source, dest).source == 2 -> 3 -> nil
move_node(source, dest).dest == 1 -> 4 -> 5 -> 6 -> nil

The push() and buildOneTwoThree() functions need not be redefined.

There is another kata called Linked Lists - Move Node In-place that is related but more difficult.

Related Kata in order of expected completion (increasing difficulty):
 Linked Lists - Push & BuildOneTwoThree
 Linked Lists - Length & Count
 Linked Lists - Get Nth Node
Linked Lists - Insert Nth Node
Linked Lists - Sorted Insert
Linked Lists - Insert Sort
Linked Lists - Append
Linked Lists - Remove Duplicates
Linked Lists - Move Node
Linked Lists - Move Node In-place
Linked Lists - Alternating Split
Linked Lists - Front Back Split
Linked Lists - Shuffle Merge
Linked Lists - Sorted Merge
Linked Lists - Merge Sort
Linked Lists - Sorted Intersect
Linked Lists - Iterative Reverse
Linked Lists - Recursive Reverse

Inspired by Stanford Professor Nick Parlante's excellent Linked List teachings.

Linked Lists
Data Structures
Fundamentals

Stats:

CreatedAug 23, 2015
PublishedAug 23, 2015
Warriors Trained4126
Total Skips568
Total Code Submissions4846
Total Times Completed1903
JavaScript Completions711
Python Completions961
Ruby Completions91
Swift Completions218
Total Stars51
% of votes with a positive feedback rating88% of 294
Total "Very Satisfied" Votes241
Total "Somewhat Satisfied" Votes38
Total "Not Satisfied" Votes15
Ad
Contributors
  • JDeBolt Avatar
  • ZozoFouchtra Avatar
  • CIS 122 Avatar
  • NaMe613 Avatar
  • Bubbler Avatar
  • user9644768 Avatar
Ad