7 kyu

Linked Lists - Append

1,215 of 3,167JDeBolt

Description:

Linked Lists - Append

Write an Append() function which appends one linked list to another. The head of the resulting list should be returned.

var listA = 1 -> 2 -> 3 -> null
var listB = 4 -> 5 -> 6 -> null
append(listA, listB) === 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null
listA = 1 -> 2 -> 3 -> null
listB = 4 -> 5 -> 6 -> null
append(listA, listB) == 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null
$list_a = 1 -> 2 -> 3 -> NULL;
$list_b = 4 -> 5 -> 6 -> NULL;
append($list_a, $list_b) // returns 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> NULL
list_a = 1 -> 2 -> 3 -> nil
list_b = 4 -> 5 -> 6 -> nil
append(list_a, list_b) == 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> nil

If both listA and listB are null/NULL/None/nil, return null/NULL/None/nil. If one list is null/NULL/None/nil and the other is not, simply return the non-null/NULL/None/nil list.

The push() and buildOneTwoThree() (build_one_two_three() in PHP and ruby) functions need not be redefined. The Node class is also predefined for you in PHP.

/* PHP Only */
class Node {
  public $data, $next;
  public function __construct($data, $next = NULL) {
    $this->data = $data;
    $this->next = $next;
  }
}

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 17, 2015
PublishedAug 19, 2015
Warriors Trained7241
Total Skips817
Total Code Submissions9938
Total Times Completed3167
JavaScript Completions1215
Python Completions1155
CoffeeScript Completions19
Swift Completions354
PHP Completions49
Ruby Completions87
Java Completions436
Total Stars100
% of votes with a positive feedback rating88% of 508
Total "Very Satisfied" Votes409
Total "Somewhat Satisfied" Votes79
Total "Not Satisfied" Votes20
Ad
Contributors
  • JDeBolt Avatar
  • marko-bekhta Avatar
  • CIS 122 Avatar
  • NaMe613 Avatar
  • CorsaiR Avatar
  • donaldsebleung Avatar
  • Bubbler Avatar
  • user9644768 Avatar
Ad