7 kyu

Linked Lists - Push & BuildOneTwoThree

2,403 of 6,424JDeBolt

Description:

Linked Lists - Push & BuildOneTwoThree

Write push() and buildOneTwoThree() functions to easily update and initialize linked lists. Try to use the push() function within your buildOneTwoThree() function.

Here's an example of push() usage:

var chained = null
chained = push(chained, 3)
chained = push(chained, 2)
chained = push(chained, 1)
push(chained, 8) === 8 -> 1 -> 2 -> 3 -> null
Node chained = null;
chained = Node.Push(chained, 3);
chained = Node.Push(chained, 2);
chained = Node.Push(chained, 1);
Node.Push(chained, 8) => 8 -> 1 -> 2 -> 3 -> null
chained1 = nil
chained2 = push chained1 3
chained3 = push chained2 2
chained4 = push chained3 1
push chained4 8 # 8 -> 1 -> 2 -> 3 -> nil

The push function accepts head and data parameters, where head is either a node object or null/None/nil. Your push implementation should be able to create a new linked list/node when head is null/None/nil.

The buildOneTwoThree function should create and return a linked list with three nodes: 1 -> 2 -> 3 -> null

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.

I'm aware that there are better ways to create linked lists (class methods, reference pointers, etc.), but not all languages have the same features. I'd like to keep the basic API consistent between language translations for this kata.

Linked Lists
Fundamentals

Stats:

CreatedAug 2, 2015
PublishedAug 2, 2015
Warriors Trained16787
Total Skips2763
Total Code Submissions19057
Total Times Completed6424
JavaScript Completions2403
Python Completions2400
Ruby Completions351
CoffeeScript Completions32
PHP Completions184
Swift Completions614
Java Completions445
C# Completions286
λ Calculus Completions18
Total Stars346
% of votes with a positive feedback rating82% of 889
Total "Very Satisfied" Votes638
Total "Somewhat Satisfied" Votes174
Total "Not Satisfied" Votes77
Ad
Contributors
  • JDeBolt Avatar
  • CIS 122 Avatar
  • NaMe613 Avatar
  • donaldsebleung Avatar
  • dinglemouse Avatar
  • Souzooka Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • Kacarott Avatar
  • Just4FunCoder Avatar
  • avermakov Avatar
Ad